Hello, perhaps you need to open the document in Write Mode; I paste something I've found:
Const ForReading = 1 Const ForWriting = 2
Set objFSo = CreateObject("Scripting.FileSystemObject") Set objFile = objFSO.OpenTextFile("c:\scripts\test.txt", ForWriting)
"Gordon" wrote:
[Quoted Text] > I am relatively new to scripting, but need to write a script to open a file > in Word and make some changes to it. > > This code fragment shows the pertinent parts: > > Set objWord = CreateObject("Word.Application") > Set objDoc = objWord.Documents.Open("d:\test.txt") > > objWord.Visible = True > > with objWord.Selection.Find > .ClearFormatting > .Text = "July" > .Replacement.Text = "August" > .Forward = True > .Wrap = wdFindContinue > .Format = True > .MatchCase = False > .MatchWholeWord = False > .MatchAllWordForms = False > .MatchSoundsLike = False > .MatchWildcards = False > end With > objWord.Selection.Find.Execute Replace:=wdReplaceAll > > The Text and Replacement.Text strings may change, but that is not the problem. > > When I attempt to run this, I get an error message on the : in the last > line. The error is a VBScript compilation error and says "Error: Expected > statement". The find and replace part is taken directly from the Word macro > recorder, and I added the "objWord." part. I suspect I need to quote the : > somehow, but don't know how. If I change this to be a find, it works fine. > > Any ideas? >
|