Discussion:
Word Automation with VBScript Does Not Work
(too old to reply)
Tony_VBACoder
2006-06-29 16:32:01 UTC
Permalink
I am trying to run client-side VBScript to launch Word, and having a problem
getting Word to open a file or even be shown. My sample code is below, and
is run from a very simple ASP page that calls this script. I am able to get
the Word object created, but cannot get it to load my file. I have added
some Response.Write statements to debug my code. Does anybody have any ideas?

The error I get when I try to run "objWord.Documents.Open" is:

Microsoft Word error '800a1066'
Command failed

======= My Sample Code ======================
' Create an instance of Word
Dim objWord ' As Word.Application
Dim objWordDoc ' As Word.Document
Dim objWordDocs ' As Word.Documents

Set objWord = CreateObject("Word.Application")
objWord.Visible = true
If objWord Is Nothing Then
Response.Write ("objWord NOT Created<BR>")
Else
Response.Write ("objWord Created<BR>")
End If

Set objWordDocs = objWord.Documents
If objWordDocs Is Nothing Then
Response.Write ("objWordDocs NOT Created<BR>")
Else
Response.Write ("objWordDocs Created<BR>")
End If

' Store the current active printer so we can reset it later.
Dim sPrevPrinter
sPrevPrinter = objWord.ActivePrinter
Response.Write ("sPrevPrinter = " & sPrevPrinter & "<BR>")
Response.Write ("Opening File: " & sDefaultDir & "TestDocument.doc<BR>")

' Open the Word document
objWord.Documents.Open sDefaultDir & "TestDocument.doc"
Walter Zackery
2006-06-29 16:57:51 UTC
Permalink
In your statement :

objWord.Documents.Open sDefaultDir & "TestDocument.doc"

what is the value of sDefaultDir? Does it point to a valid directory? Does
the string end with a backslash?
Post by Tony_VBACoder
I am trying to run client-side VBScript to launch Word, and having a problem
getting Word to open a file or even be shown. My sample code is below, and
is run from a very simple ASP page that calls this script. I am able to get
the Word object created, but cannot get it to load my file. I have added
some Response.Write statements to debug my code. Does anybody have any ideas?
Microsoft Word error '800a1066'
Command failed
======= My Sample Code ======================
' Create an instance of Word
Dim objWord ' As Word.Application
Dim objWordDoc ' As Word.Document
Dim objWordDocs ' As Word.Documents
Set objWord = CreateObject("Word.Application")
objWord.Visible = true
If objWord Is Nothing Then
Response.Write ("objWord NOT Created<BR>")
Else
Response.Write ("objWord Created<BR>")
End If
Set objWordDocs = objWord.Documents
If objWordDocs Is Nothing Then
Response.Write ("objWordDocs NOT Created<BR>")
Else
Response.Write ("objWordDocs Created<BR>")
End If
' Store the current active printer so we can reset it later.
Dim sPrevPrinter
sPrevPrinter = objWord.ActivePrinter
Response.Write ("sPrevPrinter = " & sPrevPrinter & "<BR>")
Response.Write ("Opening File: " & sDefaultDir & "TestDocument.doc<BR>")
' Open the Word document
objWord.Documents.Open sDefaultDir & "TestDocument.doc"
Tony_VBACoder
2006-06-29 18:04:02 UTC
Permalink
Yes, it is a valid directory - that is why I put in that Response.Write to
check to see if the file does in fact exist.
Post by Tony_VBACoder
objWord.Documents.Open sDefaultDir & "TestDocument.doc"
what is the value of sDefaultDir? Does it point to a valid directory? Does
the string end with a backslash?
Post by Tony_VBACoder
I am trying to run client-side VBScript to launch Word, and having a problem
getting Word to open a file or even be shown. My sample code is below, and
is run from a very simple ASP page that calls this script. I am able to get
the Word object created, but cannot get it to load my file. I have added
some Response.Write statements to debug my code. Does anybody have any ideas?
Microsoft Word error '800a1066'
Command failed
======= My Sample Code ======================
' Create an instance of Word
Dim objWord ' As Word.Application
Dim objWordDoc ' As Word.Document
Dim objWordDocs ' As Word.Documents
Set objWord = CreateObject("Word.Application")
objWord.Visible = true
If objWord Is Nothing Then
Response.Write ("objWord NOT Created<BR>")
Else
Response.Write ("objWord Created<BR>")
End If
Set objWordDocs = objWord.Documents
If objWordDocs Is Nothing Then
Response.Write ("objWordDocs NOT Created<BR>")
Else
Response.Write ("objWordDocs Created<BR>")
End If
' Store the current active printer so we can reset it later.
Dim sPrevPrinter
sPrevPrinter = objWord.ActivePrinter
Response.Write ("sPrevPrinter = " & sPrevPrinter & "<BR>")
Response.Write ("Opening File: " & sDefaultDir & "TestDocument.doc<BR>")
' Open the Word document
objWord.Documents.Open sDefaultDir & "TestDocument.doc"
Jason
2006-06-30 17:18:53 UTC
Permalink
Ummm.... ASP runs server side, so it won't launch Word on the user's
computer. It is going to try and launch it under the context of the IIS
account. Typically that account isn't allowed desktop interaction, so
attempts to actually create a seperate process will most certainly
fail.

- Jason
Post by Tony_VBACoder
I am trying to run client-side VBScript to launch Word, and having a problem
getting Word to open a file or even be shown. My sample code is below, and
is run from a very simple ASP page that calls this script. I am able to get
the Word object created, but cannot get it to load my file. I have added
some Response.Write statements to debug my code. Does anybody have any ideas?
Microsoft Word error '800a1066'
Command failed
======= My Sample Code ======================
' Create an instance of Word
Dim objWord ' As Word.Application
Dim objWordDoc ' As Word.Document
Dim objWordDocs ' As Word.Documents
Set objWord = CreateObject("Word.Application")
objWord.Visible = true
If objWord Is Nothing Then
Response.Write ("objWord NOT Created<BR>")
Else
Response.Write ("objWord Created<BR>")
End If
Set objWordDocs = objWord.Documents
If objWordDocs Is Nothing Then
Response.Write ("objWordDocs NOT Created<BR>")
Else
Response.Write ("objWordDocs Created<BR>")
End If
' Store the current active printer so we can reset it later.
Dim sPrevPrinter
sPrevPrinter = objWord.ActivePrinter
Response.Write ("sPrevPrinter = " & sPrevPrinter & "<BR>")
Response.Write ("Opening File: " & sDefaultDir & "TestDocument.doc<BR>")
' Open the Word document
objWord.Documents.Open sDefaultDir & "TestDocument.doc"
Tony_VBACoder
2006-07-03 19:10:02 UTC
Permalink
Yup...that is exactly what was happening. I got server side and client side
mixed up. Once I wrapped it in my client side code <script
Language="VBScript">, it worked fine.

Thanks.
Post by Jason
Ummm.... ASP runs server side, so it won't launch Word on the user's
computer. It is going to try and launch it under the context of the IIS
account. Typically that account isn't allowed desktop interaction, so
attempts to actually create a seperate process will most certainly
fail.
- Jason
Post by Tony_VBACoder
I am trying to run client-side VBScript to launch Word, and having a problem
getting Word to open a file or even be shown. My sample code is below, and
is run from a very simple ASP page that calls this script. I am able to get
the Word object created, but cannot get it to load my file. I have added
some Response.Write statements to debug my code. Does anybody have any ideas?
Microsoft Word error '800a1066'
Command failed
======= My Sample Code ======================
' Create an instance of Word
Dim objWord ' As Word.Application
Dim objWordDoc ' As Word.Document
Dim objWordDocs ' As Word.Documents
Set objWord = CreateObject("Word.Application")
objWord.Visible = true
If objWord Is Nothing Then
Response.Write ("objWord NOT Created<BR>")
Else
Response.Write ("objWord Created<BR>")
End If
Set objWordDocs = objWord.Documents
If objWordDocs Is Nothing Then
Response.Write ("objWordDocs NOT Created<BR>")
Else
Response.Write ("objWordDocs Created<BR>")
End If
' Store the current active printer so we can reset it later.
Dim sPrevPrinter
sPrevPrinter = objWord.ActivePrinter
Response.Write ("sPrevPrinter = " & sPrevPrinter & "<BR>")
Response.Write ("Opening File: " & sDefaultDir & "TestDocument.doc<BR>")
' Open the Word document
objWord.Documents.Open sDefaultDir & "TestDocument.doc"
Loading...