Search and replace with CreateSearchInfo

A

Andreas Haider

The following code should search for strings like X0, X1,... X9 (using
regular a expression) and make them bold. However, it does not work.
The query string was created by saving the a search/replace into a
..fpq file. I cannot find out how to search for text and replace it
with HTML code. Bug?

Thanks for any suggestions!

Dim objSearch As SearchInfo
Dim objRange As IHTMLTxtRange
Dim blnMatches As Boolean
Dim strQuery As String

strQuery = "<?xml version=""1.0"" encoding=""utf-8"" ?>" & _
"<fpquery version=""1.0"">" & _
"<queryparams regexp=""true"" />" & _
"<find text=""(X[0-9])"" />" & _
"<replace html=""&lt;b&gt;\0&lt;/b&gt;"" />" & _
"</fpquery>"

Set objRange = ActiveDocument.Selection.createRange
Set objSearch = Application.CreateSearchInfo

objSearch.QueryContents = strQuery
objSearch.Action = fpSearchReplaceAllText

Application.ActiveDocument.Find objSearch, Nothing, objRange

Set objSearch = Nothing
Set objRange = Nothing
 
Top