
Word 2000 from within VB: Windows 2000: error, Windows ME: ok
The following coding runs fine with Windows ME but fails with Windows 2000.
Option Explicit
Public objWord As Word.Application
Public objDoc As Word.Document
.
Dim strOldString As String, strNewString As String
strOldString = "something old"
strNewString = "something new"
Set objWord = New Word.Application
objWord.Visible = False
Set objDoc = objWord.Documents.Open("C:\OldFile.doc")
ReplText strOldString, strNewString
objDoc.SaveAs "C:\NewFile.doc"
objDoc.Close
.
Private Sub ReplText(strStringOld As String, strStringNew As String)
objDoc.ActiveWindow.Selection.Find.ClearFormatting <===================
objDoc.ActiveWindow.Selection.Find.Replacement.ClearFormatting
With objDoc.ActiveWindow.Selection.Find
.Text = strStringOld
.Replacement.Text = strStringNew
End With
objDoc.ActiveWindow.Selection.Find.Execute Replace:=wdReplaceAll
End Sub
Execution stops at <======== or at one of the following statemensts if this
one or the next one is commented out. The error message showed is:
Run-time error '5': Invalid procedure call or argument
I am using Windows 2000 SR-3 c.q. Windows ME with Word 2000 SR-1
and Visual Basic 6.0.
Any help or hints, but especially any solution is welcome.
J. Smits