Tony_VBACoder
2006-06-29 16:32:01 UTC
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"
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"