We need to automate the creation of word documents from the command line. We
taught about creating a vbscript script that would take command line
arguments and create the word document according to those parameters.
For some reason, certain things work, otheres do not. When we try to call
some word.application or word.document methods, the script interpreters
gives an error.
Ex: Trying to run the following script by double clicking on its .vbs file
gives the following error (Translated from french):
Script: C:\insert.vbs
Line: 12
Caract: 33
Error: ')' expected
Code: 800A03EE
Source: MS vbscript compilation error
Sub FindBMark()
Dim wordApp ' As Word.Application
Dim wordDoc ' As Word.Document
Dim wordRange ' As Word.Range
Set wordApp = CreateObject("Word.Application")
Set wordDoc = wordApp.Documents.Open("C:\MyDoc.doc")
wordApp.Visible = True
wordRange = wordDoc.Goto(What:=wdGoToBookmark, Name:="City")
wordRange.InsertAfter "Quebec"
wordDoc.Save
wordApp.Quit
Set wordApp = Nothing
End Sub
Call FindBMark()
The script finds a bookmark called "city" in the document and insert the
word "Quebec" there...
If I code the script in a VBA macro (By uncommenting the 'AS
word.applicaton, etc), it works just fine. But the problem with the VBA
macros is that I can't seem to be able to call them from the command line or
pass parameters to them unattended.
I tried replacing the wdGoToBookmark by its value but it did not work either