Click to See Complete Forum and Search --> : Do search-and-replace with a Word-object


Frank Zdarsky
February 25th, 1999, 04:18 PM
I use the following code (VB6.0) in an ActiveX-DLL to open a Word document, replace some text and print the document. Printing works fine, but the text is not being replaced, only selected. If I copy the code for replacing into a Word-macro this works well.

What am I missing?


Thanks,


Frank


-----

Public Sub PrintMyForm()



Set oWord = CreateObject("Word.Application")



oWord.Visible = True

oWord.Documents.Open "c:/MyForm.doc"



With oWord.Selection.Find

.ClearFormatting

.Replacement.ClearFormatting

.Text = ""

.Replacement.Text = "John Doe"

.Forward = True

.Wrap = wdFindContinue

.Format = False

.MatchCase = False

.MatchWholeWord = False

.MatchWildcards = False

.MatchSoundsLike = False

.MatchAllWordForms = False

.Execute Replace:=wdReplaceAll

End With



oWord.PrintOut

End Sub