Word 2007 SaveAs Automation

C

Claude Hunter

I am rewritting a Delphi 7 Word 2003 automation program that will not run
properly in Vista with Word 2007. I'm using Delphi 2009, Vista Enterprise,
and Word 2007.

Everything in the program works fine (creating a document, inserting text,
formating test, inserting tables, etc.) except when I attempt to use the
SaveAs procedure (WordApplication.ActiveDocument.SaceAs). The Word 2007
always throws an exception at the point. The following is the Delphi code
I'm using to call the SaveAs proceudre. Since I'm using early binding in
Delphi, I must supply all parameters.

WordApp.Connect;
WordApp.Visible := True;
SaveFile := 'C:\Users\Administrator\Documents\WordTest.docx';
WordApp.ActiveDocument.SaveAs(SaveFile,
EmptyParam,
EmptyParam,
EmptyParam,
EmptyParam,
EmptyParam,
EmptyParam,
EmptyParam,
EmptyParam,
EmptyParam,
EmptyParam,
EmptyParam,
EmptyParam,
EmptyParam,
EmptyParam);

I have tried everything to solve this. I've asked for help on the Delphi
forums and no one there seems to have this problem. The U.S. government
office I work for is very strict with computer/network security. Is there
anything in the Word 2007 Trust Center settings that could affect this?

Claude Hunter
 
C

Cindy M.

Hi =?Utf-8?B?Q2xhdWRlIEh1bnRlcg==?=,
I am rewritting a Delphi 7 Word 2003 automation program that will not run
properly in Vista with Word 2007. I'm using Delphi 2009, Vista Enterprise,
and Word 2007.

Everything in the program works fine (creating a document, inserting text,
formating test, inserting tables, etc.) except when I attempt to use the
SaveAs procedure (WordApplication.ActiveDocument.SaceAs). The Word 2007
always throws an exception at the point.
And what is the exception?

As far as I can see, there are no problems with your code. I didn't count the
number of parameters, though, and compare them with the 2007 SaveAs method
signature. Did you?

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
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 :)
 
C

Claude Hunter

Manvir Singh said:
Hi Claude,

Cindy's doubt is correct; there is one parameter less from the total count
(16).

Here is the link to the documentation of "Save As" function:
http://msdn.microsoft.com/en-us/library/bb221597.aspx

Regards,
Manvir Singh
I appreicate the comments. My sample above must have been a typo. I have
the correct number of parameters in my real code. I have tried this in
Microsoft C# and Visual Basic with the same results. In VB you do not have
to include all parameters but I still get the same error.

I have a similar issue with automating Excel's "Open" command.

Unfortunately, this is not limited to just one machine. My organization
using an standard image across all machines and recently upgraded the image.
Unfrotunately, security is so tight on these systems that it is sometimes
difficult for authorized users to use them. I'm wondering if there is a
system policy setting that could be affecting this. What puzzles me is the
so far the only issues I have had with automating Office 2007 Word and Excel
is the Word "SaveAs" command and the Excel "Open" command.

Any thoughts?

Claude
 
M

Manvir Singh

What exception are you getting when you call Save As... in Word/Excel or
Close in Excel?

Also, Are you able to SaveAs... the file from the Word/Excel UI ( using
Office Button -> Save As...)?

-
Manvir Singh
 
C

Claude Hunter

Both Word and Excel return an exception error. The error information
provided by Delphi is very sparce. Visual Basic provides more information (a
lot of technical information and a stact trace) unfortunately, I'm at work
right now and do not have access to the error results returned by VB (I have
VB install at home).

The problem I have with Excel is opening a workbook ("Open" command) or
adding a workbook ("Add" command). The "Open" command will open the workbook
and then immediately return the exception error. The "Add" command will add
a new workbook and then immediately return the exception error. Nothing can
be done with the Excel workbook after this. The only option you have is to
close the workbook through the Excel UI.

The problem I have with Word is any commands for saving a document
("SaveAs," "Save," etc.). In the case of Word, the document is not saved so
the exception is happening before the command is executed.

I have developed a convoluted work around for these issues. It not pretty
though. For Excel I use ShellExecute to open files or to open Excel with a
workbook. Then I use automation to connect to the running instance of Excel.
All automation works fine in this method.

In Word, I use Delphi's CopyFile method to copy, move, and rename the
document I want to work with. This ensures that the original document is not
overwritten. Then I open the document using automation and execute my
automation code. The only issue here is the the user must ensure that the
manually save changes.

Both Word and Excel work normally. There are no issues with opening or
saving files through the UIs.

Claude
 
C

Cindy M.

Hi Claude,
I have developed a convoluted work around for these issues. It not pretty
though. For Excel I use ShellExecute to open files or to open Excel with a
workbook. Then I use automation to connect to the running instance of Excel.
All automation works fine in this method.
Given this, and the fact that I've never encountered the behavior you describe,
I'd say the problem is in your "locked down" environment. Perhaps something
(anti-virus software, perhaps?) is blocking proper OLE Automation link ups. This
then would be more a Windows / Office configuration issue than a programming
issue.

Cindy Meister
INTER-Solutions, Switzerland
http://homepage.swissonline.ch/cindymeister (last update Jun 17 2005)
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 :)
 

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