I am simply trying to find text in a Word document using a string. I have the following code:
Dim mystring As String
Selection.WholeStory
Selection.Find.ClearFormatting
With Selection.Find
.Text = mystring
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
.MatchFuzzy = False
End With
Selection.Find.Execute
The variable 'mystring' has been populated earlier in the code and exactly matches the text in the document. Nothing happens on running the code.
If I add exactly the same text to the string before running the code, it works fine:
Dim mystring As String
mystring = "text marker"
Selection.WholeStory
Selection.Find.ClearFormatting
With Selection.Find
.Text = mystring
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = False
.MatchCase = False
.MatchWholeWord = False
.MatchByte = False
.MatchAllWordForms = False
.MatchSoundsLike = False
.MatchWildcards = False
.MatchFuzzy = False
End With
Selection.Find.Execute
There has to be something simple that I am missing. Any help would much appreciated. Thanks.