Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Word 2007 SaveAs Automation

152 views
Skip to first unread message

Hunter@discussions.microsoft.com Claude Hunter

unread,
Jan 25, 2009, 4:18:01 AM1/25/09
to
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


Cindy M.

unread,
Jan 28, 2009, 9:46:12 AM1/28/09
to
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 :-)

Manvir Singh

unread,
Jan 28, 2009, 4:01:14 PM1/28/09
to
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

Hunter@discussions.microsoft.com Claude Hunter

unread,
Jan 28, 2009, 5:20:04 PM1/28/09
to

"Manvir Singh" wrote:

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

Manvir Singh

unread,
Jan 29, 2009, 12:00:43 PM1/29/09
to

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

Claude Hunter

unread,
Jan 29, 2009, 5:15:00 PM1/29/09
to
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

Cindy M.

unread,
Feb 13, 2009, 1:21:42 PM2/13/09
to
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.

Michael

unread,
Nov 4, 2010, 3:38:29 PM11/4/10
to
Hi Claude,

Did your problem got resolved. We are exeperiencing the same problem. We would like to know your resolution.

Thanks,
Michael

> On Sunday, January 25, 2009 4:18 AM Claude Hunte wrote:

> 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


>> On Wednesday, January 28, 2009 9:46 AM Cindy M. wrote:

>> Hi =?Utf-8?B?Q2xhdWRlIEh1bnRlcg==?=,


>>
>> 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 :-)


>>> On Wednesday, January 28, 2009 4:01 PM manvi wrote:

>>> 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


>>>> On Wednesday, January 28, 2009 5:20 PM Claude Hunte wrote:

>>>> "Manvir Singh" wrote:
>>>>
>>>> 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


>>>>> On Thursday, January 29, 2009 12:00 PM manvi wrote:

>>>>> 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


>>>>>> On Thursday, January 29, 2009 5:15 PM ClaudeHunte wrote:

>>>>>> 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
>>>>>>
>>>>>> "Manvir Singh" wrote:


>>>>>>> On Friday, February 13, 2009 1:21 PM Cindy M. wrote:

>>>>>>> Hi Claude,


>>>>>>>
>>>>>>> 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 :-)


>>>>>>> Submitted via EggHeadCafe - Software Developer Portal of Choice
>>>>>>> Update Configuration of a ClickOnce WPF Application Using Mage or MageUI
>>>>>>> http://www.eggheadcafe.com/tutorials/aspnet/a8788ed5-c1b5-41d5-b49c-ea4760c3b820/update-configuration-of-a-clickonce-wpf-application-using-mage-or-mageui.aspx

0 new messages