Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Word automation find and replace
Message
De
02/12/2004 08:48:40
 
 
À
02/12/2004 03:06:22
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Divers
Thread ID:
00966187
Message ID:
00966357
Vues:
17
Hi

Thanks to all of you for the reply. Now I can search and replace all over my word document.

Thanks again

Michel


>Michel,
>
>I use the routine below. It works in headers. Give it a try
>
>
>
>*----------------------------------------------------
>function SearchAndReplace_Word
>	lparameters	WordObj, SearchFor, ReplaceWith, MatchCase, MatchWholeWord, ;
>				MatchWildCards, MatchSoundsLike, MatchAllWordForms, FormatInfoAlso
>
>	#define wdFindStop     0
>	#define wdFindContinue 1
>	#define wdFindAsk      2
>
>	#define wdReplaceNone  0
>	#define wdReplaceOne   1
>	#define wdReplaceAll   2
>
>	local Forward, Wrap
>	
>	for each StoryRange in WordObj.ActiveDocument.StoryRanges
>		with StoryRange
>			.WholeStory
>			.Find.ClearFormatting
>			.Find.Replacement.ClearFormatting
>		
>			Forward = TRUE
>			Wrap = wdFindContinue
>			
>			&& replacement max 254 chars
>			do case
>			case len(ReplaceWith) <= 254
>				=StoryRange.Find.Execute(SearchFor, MatchCase, MatchWholeWord, MatchWildCards, MatchSoundsLike, MatchAllWordForms, Forward, Wrap, FormatInfoAlso, ReplaceWith, wdReplaceAll, , , , )
>			otherwise
>				local x, xReplace, ReplaceLeft
>				ReplaceLeft = ReplaceWith
>				
>				do while !empty(len(ReplaceLeft) )
>					do case
>					case len(ReplaceLeft) < 255
>						xReplace = ReplaceLeft
>						ReplaceLeft = ''
>					otherwise
>						xReplace = left(ReplaceLeft, 254 - len(SearchFor)) + SearchFor
>						ReplaceLeft = Substr(ReplaceLeft, 254 - len(SearchFor) + 1)
>					endcase
>					
>					=StoryRange.Find.Execute(SearchFor, MatchCase, MatchWholeWord, MatchWildCards, MatchSoundsLike, MatchAllWordForms, Forward, Wrap, FormatInfoAlso, xReplace, wdReplaceAll, , , , )
>			
>				enddo
>			endcase
>		endwith
>	endfor
>	#undefine wdFindStop
>	#undefine wdFindContinue
>	#undefine wdFindAsk
>
>	#undefine wdReplaceNone
>	#undefine wdReplaceOne
>	#undefine wdReplaceAll
>endfunc
>*--------------------------------------------------------------------------
>
>>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