Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Word automation and Find
Message
 
À
Tous
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Word automation and Find
Divers
Thread ID:
01676077
Message ID:
01676077
Vues:
69
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
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform