Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Word automation find and replace
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00966187
Message ID:
00966242
Vues:
11
Mike,

Not sure this is perfect, but this is what I do. It gets all of the headers, footers and any text blocks within the specified "section" of the document. A section break in Word is what seperates the individual letters in a mail merge. The .ReplaceRange() method does the search and replace.
       ***Get the last section
	losection=this.odocument.sections[this.odocument.sections.count]
	IF varTYPE(losection)='O'
		this.replacerange(losection.range)

		WITH losection
                      ****replace in any text blocks
			IF TYPE('losection.range.shaperange')='O'
				lntotal=.Range.ShapeRange.count
				FOR lncnt=1 TO lntotal
					lorange= .Range.ShapeRange.Item[lncnt]
					IF varTYPE(lorange)='O'
						lorange=lorange.TextFrame.TextRange
						IF varTYPE(lorange)='O'
							this.replacerange(lorange)						
						endif
					endif	
				endfor			
			ENDIF

                     *******replace in any footers
			IF TYPE('losection.footers')='O'
				lntotal=.footers.count
				FOR lncnt=1 TO lntotal
					lorange=.footers[lncnt].range	
					IF varTYPE(lorange)='O'
						this.replacerange(lorange)						
					endif	
				endfor	
			ENDIF	

                     *******replace in any headers
			IF TYPE('losection.headers')='O'
				lntotal=.headers.count
				FOR lncnt=1 TO lntotal
					lorange=.headers[lncnt].range	
					IF varTYPE(lorange)='O'
						this.replacerange(lorange)						
					endif	
				endfor	
			ENDIF	
		ENDWITH
		losection=this.odocument.sections[1]
		losection.range.select
	ENDIF	
>Hi
>
>I must do find and replace using OLE automation with Word. I have some code who is working but just in the body of the document. I am not able to find and replace in header and footer. I need to make word search in the whole document including header and footer.
>
>Here is a sample of my code.
>
> LOCAL oWord AS "Word.Application"
> IF TYPE("oWord") <> "O"
> oWord = CREATEOBJECT("Word.Application")
> ENDIF
> oWord.Documents.Open("d:\transit2.doc")
> oWord.VISIBLE = .t.
> loSelection = oWord.ActiveWindow.ActivePane.SELECTION
> loSelection.FIND.ClearFormatting()
>
> WITH loSelection.FIND
> .TEXT = "@Transit"
> .Replacement.TEXT = "81599999"
> .Forward = .T.
> .FORMAT = .F.
> .MatchCase = .F.
> .MatchWholeWord = .F.
> .MatchWildcards = .F.
> .MatchSoundsLike = .F.
> .MatchAllWordForms = .F.
> ENDWITH
> loSelection.FIND.Execute(,,,,,,,,,,2)
>
>Thanks
>
>Mike
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform