/ Forums / Advansys Formativ / Creating Solutions with Formativ / Search and Replace in MS Word / Reply To: Search and Replace in MS Word
November 23, 2003 at 3:44 pm
#6774
I believe that using the selection object (.ActiveDocument) in Word is unreliable. Also, neither VBScript nor Formativ know the Word constant wdReplaceAll.
The following code sample should be a useful alternative.
Advansys Support
Const wdReplaceAll = 2 '------------------------------------------------------------------------------- ' Mainline processing '------------------------------------------------------------------------------- Sub Main(Client, GWEvent) dim oRange dim oWordObj On error resume next Set oWordObj = CreateObject("Word.Application") if oWordObj is nothing then exit sub end if oWordObj.Documents.open("c:temptest.doc") oWordObj.visible = true Set oRange = oWordObj.Documents(1).Content if oRange is nothing then exit sub end if Call oRange.Find.Execute("%1",FALSE,TRUE, FALSE,,,TRUE,FALSE,FALSE,"Argl",wdReplaceAll) set oRange = nothing set oWordObj = nothing End Sub