I found this question on Google and the code in the question did not work for me. I fixed the following changes:
- I changed
Selection.Find.Style = "Heading 1" to an object. - I changed the code to capture the boolean search result from
.Execute , not .Found
I hope this helps some other google.
With ThisDocument.Range.Find .Text = "The Heading" .Style = ActiveDocument.Styles("Heading 1") Dim SearchSuccessful As Boolean SearchSuccessful = .Execute If SearchSuccessful Then ' code Else ' code End If End With
source share