Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Word automation and Find
Message
From
11/09/2020 01:24:03
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
01676077
Message ID:
01676093
Views:
58
I am not sure if that makes the difference, but I would not work with Selection, but instead with Range object.

Try the following if that is working:
loWord = CREATEOBJECT("Word.application")
loDoc = loWord.Documents.Open("c:\Files\Home.docx")
loRange = loDoc.Content
loRange.Find.ClearFormatting()
loRange.Find.Replacement.ClearFormatting()
loRange.Find.Execute("^g",.F.,.F.,.F.,.F.,.F.,.T.,1,.F.,"",2,.F.,.F.,.F.,.F.)
As to the result, the range object will be changed:
loRange = loDoc.Content
loRange.Find.ClearFormatting()
loRange.Find.Replacement.ClearFormatting()
loRange.Find.Font.Bold = .T.
loRange.Find.Execute("",.F.,.F.,.F.,.F.,.F.,.T.,1,.T.,"",.F.,.F.,.F.,.F.,.F.)
?loRange.Text
?loRange.Start
?loRange.End
>Hello, I use Microsoft Office Automation by Granor and Martin, and have had great luck over the years. But I recently ran into a problem with the FoxPro automation of Word, using find.
>This works:
>
>oWord.Selection.WholeStory
>oWord.Selection.Fields.Unlink
>oWord.Selection.HomeKey(wdStory) && remove all hypinks
>
>
>The following sometimes works:
>
>** go to top of doc first
>oWord.Selection.Find.ClearFormatting && next find
>oWord.Selection.Find.Replacement.ClearFormatting
>With oWord.Selection.Find  && remove those pictures
>  .Text = "^g"
>  .Replacement.Text = " "
>EndWith
>IF oWord.Selection.Find.Found
>oWord.Selection.Find.Execute(wdReplaceAll)
>endif
>*WAIT WINDOW "pictures"
>
>
>
>And this never works and I don’t know why.
>
>oWord.Selection.HomeKey(wdStory)  && go home
>oWord.Selection.Find.ClearFormatting  && ready for find and delete
>oWord.Selection.Find.Replacement.ClearFormatting
>With oWord.Selection.Find
>  *.Text = "Print | Close Window"
>  .Text = "Print"
>  .Replacement.Text = " "
>  .replacement.paragraphFormat.leftIndent = 12
>  lFound = .execute( , , , , , , , , , , wdReplaceAll)
>*********************1       5        10*************
>EndWith
>oWord.Selection.Find.Execute(wdReplaceAll)
>
>
>On the other hand this always works:
>
>oWord.Selection.HomeKey(wdStory) && go home
>oWord.Selection.Find.ClearFormatting
>oWord.Selection.Find.Font.Bold = .F.
>oWord.Selection.Find.Replacement.ClearFormatting
>With oWord.Selection.Find
>  .Text = ""
>  .Replacement.Text = " "
>  .Forward = .F.
>  .Format = .F.
>  .MatchCase = .F.
>  .MatchWholeWord = .F.
>  .MatchWildcards = .F.
>  .MatchSoundsLike = .F.
>  .MatchAllWordForms = .F.
>EndWith
>oWord.Selection.Find.Execute
>oWord.Selection.Copy
>	** file 22
>*WAIT WINDOW "first bold title"
>
>
>Another problem I have faced, is that when the code does “find” something (as in the above), I have not been able to figure out how to pass the found text to a variable? As a result I resorted to the following, since the found text is always at the start of the document. It would be great to know how to pass found text to a variable.
>
>
>titleRange = ALLTRIM(oWord.ActiveDocument.Range(0,50).Text)
>
>
>Since I cannot upload a sample word doc I am attaching a JPEG to show what one looks like,
>
>Thanks,
>Steve Elster
Christian Isberner
Software Consultant
Previous
Reply
Map
View

Click here to load this message in the networking platform