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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top