Hi I have a macro which runs through a documents and sets hyperlinks on the text it finds. I'm finding in a number of situations that the wrong hyperlink is being set. This is because it if first finding a subset of a longer string. I.e in the example below ABC 101 is being set with the hyperlink for ABC 1.
FndArray = Array("<ABC 1.[0-9]{1,}>", "ABC 1",<ABC 101.[0-9]{1,}>", "ABC 101 ",
I am using wildcards as in some instances ABC 1 may be ABC 1.10, etc. I found putting a space after the "ABC 1 " eliminated the issuse but caused another where there was another character after it. I.e. a . or ).
Rest of the code is as follows:
With wdDoc.Content
With .Find
.ClearFormatting
.Replacement.ClearFormatting
.Text = FndArray(i)
.Replacement.Text = ""
.Forward = True
.Wrap = wdFindStop
.Format = True
.MatchWildcards = True
.Execute
End With
Do While .Find.Found = True
.Duplicate.Hyperlinks.Add Anchor:=.Duplicate, Address:=RepArray(i), _
SubAddress:="", ScreenTip:="", TextToDisplay:=""
.Start = .Duplicate.Hyperlinks(1).Range.End
.Find.Execute
Loop
End With
Hoping someone is able to assist me.
Thanks.