Home > Software engineering >  How to escape forward slash in Word VBA Find?
How to escape forward slash in Word VBA Find?

Time:01-14

I have documents containing hidden markings like these

<tag>tag content</tag>

The tags themselves use a hidden font, the content does not. I need to find the tag content but the forward slash seems to cause issues

ActiveWindow.View.ShowHiddenText = True

Find.ClearFormatting
Find.Text = "<tag>*</tag>"
Find.Forward = True
Find.Wrap = False
Find.Format = False
Find.MatchWildcards = True
Find.IgnoreSpace = True
Find.IgnorePunct = True
Find.Font.Hidden = wdUndefined
Find.Execute

When I remove the forward slash of one of the tags (and the search string of course) it works fine.

I´ve tried Find.Text = "<tag>*<\/tag>" to escape it but that does not seem to work. My MS Office language is set to english but the documents originate from a german version, not sure if that matters?

CodePudding user response:

In Word < and > are used as wildcards for the beginning and ending of a word. That's why you have to escape them as well

\<tag\>d*\<\/tag\>

  • Related