I'm writing a macro in Visual Basic (ugh, I know) to parse documents in Microsoft Word. This is the workflow I'm trying to achieve:
- Search for a string in the document (equivalent to
Edit > Find > Find...
). - Ask the user if he or she wants to replace the matching string with another string (equivalent to
Edit > Find > Replace... > Replace
, but with a confirmation dialog before performing the replacement). - If yes, do the replacement. If not, go to the next match.
I can do the finding and replacing with the Find.Execute
method:
Set myRange = ActiveDocument.Content
myRange.Find.Execute FindText:="hi", _
ReplaceWith:="hello", Replace:=wdReplaceAll
But I'm not sure how to prompt the user before performing the replacement.