Starting MS Word 2002 from VB script

R

Randy

I can start Word ok, just cannot get a blank document to come up, so when my
script runs it gets an error because it expects a blank Doc to be up.

Here is what I am doing -

Dim WordApplication As Object
Dim WordApp As Object

' Add four additional steps for initialization and post processing
OpenCancelDialog "Opening Microsoft Word", ReportOptions.TotalClasses + 4

StepCancelDialog "Opening Microsoft Word", 0

'GSB Fix exception error handling
' If an error occurs then go to the TryWord95Create label
' On Error GoTo TryWord95Create XXX revalid

' Create an instance of Word using Word 97 technique
Set WordApplication = CreateObject ("Word.Application")
Set WordApp = WordApplication.WordBasic
GoTo HaveWordApp

TryWord95Create:
'GSB Fix exception error handling
' If an error occurs then go to the CancelPressed label
' On Error GoTo CancelPressed XXX revalid

' Create an instance of Word using Word 95 technique
Set WordApp = CreateObject ("Word.Basic")

HaveWordApp:
' If an error occurs then go to the CancelPressed label
' On Error GoTo CancelPressed XXX revalid

StepCancelDialog "Loading Document Template", 1
' WordApp.FileNew TemplatePathName$
WordApp.FileNew
SubStepCancelDialog
' WordApp.FileSaveAs FileName$
 
D

Doug Robbins

Don't know why you are setting WordApp to WordApplication.WordBasic, but to
create a new document, use

WordApplication.Documents.Add

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
R

Randy

That did not work, got a run-time error -2147417851 (0x80010105) on the line
with 'WordApplication.Documents.Add'.
 
D

Doug Robbins

Did you have that after Set WordApplication = CreateObject
("Word.Application")?


--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
R

Randy

Yes, here is part of my script -

Dim WordApplication As Object
Dim WordApp As Object

' Add four additional steps for initialization and post processing
OpenCancelDialog "Opening Microsoft Word", ReportOptions.TotalClasses + 4

StepCancelDialog "Opening Microsoft Word", 0

'GSB Fix exception error handling
' If an error occurs then go to the TryWord95Create label
' On Error GoTo TryWord95Create XXX revalid

' Create an instance of Word using Word 97 technique
Set WordApplication = CreateObject ("Word.Application")
Set WordApp = WordApplication.WordBasic
GoTo HaveWordApp

TryWord95Create:
'GSB Fix exception error handling
' If an error occurs then go to the CancelPressed label
' On Error GoTo CancelPressed XXX revalid

' Create an instance of Word using Word 95 technique
Set WordApp = CreateObject ("Word.Basic")

HaveWordApp:
' If an error occurs then go to the CancelPressed label
' On Error GoTo CancelPressed XXX revalid

StepCancelDialog "Loading Document Template", 1
' WordApp.FileNew TemplatePathName$ commented out by R. Bootes
WordApp.FileNew ' added by Randy Bootes
SubStepCancelDialog
' WordApp.FileSaveAs FileName$ ' Commented out by Randy Bootes
 
D

Doug Robbins

I don't see (nor does Word's Edit>Find) "WordApplication.Documents.Add"
anywhere in your code.


--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top