I have a Windows specific request. I need to:
- Open a word document -- Done, know how to do that
- Search for a specific string and move the cursor in Word to that location.
I know how to accomplish 1. I'm stumped with 2. Here's what I know: The
Document object in Word has a
Selection[//tt] object. In turn, Selection has a Find object which can be used to search. Find, according to this article on msdn.microsoft.com, requires the following parameters:
With Selection.Find
.Forward = True
.ClearFormatting
.MatchWholeWord = True
.MatchCase = False
.Wrap = wdFindContinue
.Execute FindText:="Microsoft"
End With
Question: How do I turn this VBA code into a pascal code relying on variants?. I'm facing at least two challenges with the faulty code below:
fSelection := fDocument.Selection;
With fSelection.Find do
begin
Forward := True ; //<== Won't compile
ClearFormatting ;
MatchWholeWord := True ;
MatchCase := False ;
Wrap := wdFindContinue ;
Execute FindText:="Microsoft" ; //<== won't compile.
end;
Any suggestion you might have here would be helpful.
Also, As I go, I'm building a set of classes to wrap all this wonderful code behind a streamlined facade. If anyone is interested, let me know and I'll post it back here.
Thanks