From: hans on
Hi,

I need some help with this one:

I'd like to open a word document (testdocument.doc); adjust it and save
the document again as result.doc . I wrote the following code to
perform this action, but if I run the application, I get an error:

Microsoft Word error '800a1066'

Command failed

/pro2006/test-word.asp, line 47


Can somebody tell me what I'm doing wrong?

(I'm using office 2003 and the code is written in ASP.)


Dim sTemplateFile
Dim sTargetFile
Dim oWordApp ' Our Word application
Dim oWordDoc ' Our Word document

'File system object
Dim oFSO

sTemplateFile = Server.MapPath("\pro2006") & "\testdocument.doc"
sTargetFile = Server.MapPath("\pro2006") & "\result.doc"

'Delete old target file
Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
If oFSO.FileExists(sTargetFile) Then oFSO.DeleteFile(sTargetFile)
Set oFSO = Nothing
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title></title>
</head>
<body>
<%
'Create an instance of Word Application
set oWordApp = Server.CreateObject("Word.Application")

'Open template
set oWordDoc = oWordApp.Documents.Open(sTemplateFile) '(=> this is
line 47)

oWordApp.visible = false
oWordApp.DisplayAlerts = false

'Save document
oWordApp.ActiveDocument.SaveAs sTargetFile

'Quit Word
set oWordDoc = Nothing
oWordApp.Quit
set oWordApp = Nothing

From: Jay Freedman on
Hi Hans,

I don't have a specific answer for you, but I recommend the article
"Considerations for server-side Automation of Office" at
http://support.microsoft.com/?kbid=257757 that may explain what's happening
and what you can do instead.

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.

hans wrote:
> Hi,
>
> I need some help with this one:
>
> I'd like to open a word document (testdocument.doc); adjust it and
> save the document again as result.doc . I wrote the following code to
> perform this action, but if I run the application, I get an error:
>
> Microsoft Word error '800a1066'
>
> Command failed
>
> /pro2006/test-word.asp, line 47
>
>
> Can somebody tell me what I'm doing wrong?
>
> (I'm using office 2003 and the code is written in ASP.)
>
>
> Dim sTemplateFile
> Dim sTargetFile
> Dim oWordApp ' Our Word application
> Dim oWordDoc ' Our Word document
>
> 'File system object
> Dim oFSO
>
> sTemplateFile = Server.MapPath("\pro2006") & "\testdocument.doc"
> sTargetFile = Server.MapPath("\pro2006") & "\result.doc"
>
> 'Delete old target file
> Set oFSO = Server.CreateObject("Scripting.FileSystemObject")
> If oFSO.FileExists(sTargetFile) Then oFSO.DeleteFile(sTargetFile)
> Set oFSO = Nothing
> %>
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
> <html>
> <head>
> <title></title>
> </head>
> <body>
> <%
> 'Create an instance of Word Application
> set oWordApp = Server.CreateObject("Word.Application")
>
> 'Open template
> set oWordDoc = oWordApp.Documents.Open(sTemplateFile) '(=> this is
> line 47)
>
> oWordApp.visible = false
> oWordApp.DisplayAlerts = false
>
> 'Save document
> oWordApp.ActiveDocument.SaveAs sTargetFile
>
> 'Quit Word
> set oWordDoc = Nothing
> oWordApp.Quit
> set oWordApp = Nothing


From: Cindy M -WordMVP- on
Hi Hans,

Since you're using Word 2003, and this is server-side, may I suggest that
the document be saved as Word XML? Then you can manipulate the XML using
the standard XML tools, without having to open the document in Word. That
should also be a lot faster than automating Word :-)

> I'd like to open a word document (testdocument.doc); adjust it and save
> the document again as result.doc . I wrote the following code to
> perform this action, but if I run the application, I get an error:
>
> Microsoft Word error '800a1066'
>
> Command failed
>
> /pro2006/test-word.asp, line 47
>
>
> Can somebody tell me what I'm doing wrong?
>
> (I'm using office 2003 and the code is written in ASP.)
>

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 8 2004)
http://www.word.mvps.org

This reply is posted in the Newsgroup; please post any follow question or
reply in the newsgroup and not by e-mail :-)

From: hans on
Cindy,

I have to use the word automation for this one, so xml isn't a solution
for me.
I'm sure this is something stupid, but i simply don't see what's going
wrong... . I don't manage to open the document (or even create a blank
document).

From: hans on
Hi,

I was able to solve the problem. We had to adjust our security settings
as described in the article that Jay mentioned in his post...
Thx a lot for your help!!!

Hans