Receiving automation error only when late bound

H

Heide

Here's the code.

objword.Documents(strActivateName).SaveAs FileName:=strFullFileName,
FileFormat:=mgwdFormatXML
objword.Documents(strActivateName).Activate

When I deploy this early bound all is right with the world. The
application test out successfully.

For corporate purposes, we deploy late bound. When I compile and test
late bound the first line executes correctly, err.number is 0,
err.description is blank and the file in the file system looks
perfect.

However, executing *any* automation command after this results in the
following error. (it's not just the .activate)

?err.Number
-2147417851
?err.Description
Automation error
The server threw an exception.

I am using:
Visual Basic 6.3
Windows XP Professional version 2002 Service Pack 1
Microsoft Office Word 2003 (11.6359.6360) Service Pack 1

Any insight is appreciated.

Thank you,
Heide
 
C

Cindy M -WordMVP-

Hi Heide,

What if you don't explicitly name the arugments (leave out Filename:=
and FileFormat:=), separating the arugments with commas, instead (with
"empty commas" for arguments you don't use)?

Are you certain strActivateName is a valid document name? snd
strFullFileName a valid file path?

Can you see the objword window? Are you sure that Word isn't waiting
for the user to answer a dialog box?
objword.Documents(strActivateName).SaveAs FileName:=strFullFileName,
FileFormat:=mgwdFormatXML
objword.Documents(strActivateName).Activate

When I deploy this early bound all is right with the world. The
application test out successfully.

For corporate purposes, we deploy late bound.

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

Heide

Hello Cindy,

What if you don't explicitly name the arugments (leave out Filename:=
and FileFormat:=), separating the arugments with commas, instead (with
"empty commas" for arguments you don't use)?

By switching my project to early bound everything works.
Are you certain strActivateName is a valid document name? snd
strFullFileName a valid file path?

Yes and yes. Interrogating the values while in debug they are correct and
the file does save without returning an error but *ANY* automation command
that follows blows up with Server threw an exception. Checking the file
afterwards - it is valid and it the right place. Only additional processing
cannot continue. The save throws no error at all, only the commands that
follow.

Again - early bound everything is perfect.
Can you see the objword window? Are you sure that Word isn't waiting
for the user to answer a dialog box?

Yes, I can. There is no dialog box. Everything appears perfectly normal
after the saveas. All err information is normal.

Thanks for the questions - it helps to really poke at these. It strikes me
as very odd that early bound everything is fine. Is there some difference
between early/late bind related to saveas or xml or sunspots? :)

Heide
 
H

Heide

A little more background.

objword.Documents(strActivateName).SaveAs FileName:=strFullFileName,
FileFormat:=mgwdFormatXML

Earlier on in the process we create a new document, strActivateName is
DOCUMENT.XML. By the time we reach these commands we have determined the
name the document will have in our archive, strFullFileName is the new name
and we need to save it as XML, hence the FileFormat.

If I simply left off FileName:= and FileFormat:= I wouldn't have the
correct name in my archive and the file would not be in XML format.

I find it very odd, when either late bound or early bound, the .saveas is
working as I expect it to and throws no errors. It's only any other
automation command that is issued later when late bound that throws an
exception.
 
C

Cindy M -WordMVP-

Hi =?Utf-8?B?SGVpZGU=?=,
If I simply left off FileName:= and FileFormat:= I wouldn't have the
correct name in my archive and the file would not be in XML format.
I didn't mean to leave the information away, I meant don't use named
arguments; list the arguments, only. Roughly

doc.SaveAs strFileName, mgwdFormatXML

Late-binding can't use constant enums, as you're aware (MGwdFormatXML:
you've obviously assigned a value to this somewhere in your code). Perhaps
it's also balking at the named arguments.
I find it very odd, when either late bound or early bound, the .saveas is
working as I expect it to and throws no errors. It's only any other
automation command that is issued later when late bound that throws an
exception.
That's what makes me think there are problems actually EXECUTING the
.SaveAs. One other thing: how are you declaring and assigning objword (the
application object variable)? And is there any chance that the late-binding
is somehow picking up a different version's object library (one where XML
format is not supported)?

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

Tina

Hi,
Heide is in Aruba! I am reviewing your comments.

I tried your suggestions regarding the parameter list. I left out the
FileName:= and FileFormat:= and changed the project back to late bound
and still got the error ( -2147417851 The server threw an exception.
).

The error object is 0 after this call to .SaveAs. Any line after that
will throw the above exception. Any other ideas?

Thanks so much.
 
C

Cindy M -WordMVP-

Hi Tina,

Hmmm. Yesterday I was working on automating an embedded Excel object in
Word, using late binding, and ran into something similar BUT ONLY when
stepping through or debugging the code. As long as it ran right through,
there was no problem.

If that doesn't apply to your case, I'd like to test your scenario.
However, I'm rather busy, at the moment, so if you could put together a
small procedure (declare the variables, instantiate the application
object, etc.) that shows the problem, then copy/paste that into a
message, I'd be happy to try it out. If I get the same problem, I'll
open a support issue and we can try to see what's what.
I tried your suggestions regarding the parameter list. I left out the
FileName:= and FileFormat:= and changed the project back to late bound
and still got the error ( -2147417851 The server threw an exception.
).

The error object is 0 after this call to .SaveAs. Any line after that
will throw the above exception. Any other ideas?

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

Tina

Cindy,
Thanks so much for your replies.

We've been researching this and found some information that I think is
pertinent.

This is what we are doing.

Prior to opening a document in Microsoft Word, we make a copy (file
system copy) of a Word Template. We name the copy Document.XML. So
the origins of the document begin with a template. If I open
Document.XML (the template/document) in stand alone Word and then try
to close it, I get a popup saying "Sub or Function not defined."
However, I do not see any issues with References and cannot step into
whatever function it is complaining about. So I think that it is this
automation error that is causing the problem. I do not believe that
it is a sub or function that our team has created. I believe it is
probably one of the automatically generated Word macros (in this case,
AutoClose).

After doing some research, it seems like this problem happens when
opening templates created in prior versions of Word or if Normal.dot
is corrupt.

I have made sure normal.dot is not corrupt and there are no extraneous
templates in my startup folders for Office.

I cannot step into the macros so I cannot find out what it is
complaining about. I also cannot delete or rename the macro.

Does any of this sound familiar to you?


I can reproduce the problem quite easily but have no ideas on how to
eliminate it. If I create a new template, I do not get the problem.
We have many templates with tons of styles and macros and I hope that
re-creating them is not the solution.

I can give you the code, but the template I believe is the issue. How
should I proceed? Should I email you the template?

Thanks for any asistance with this.

Tina
 
C

Cindy M -WordMVP-

Hi Tina,

Hmmm, interesting. If I were in your place, there are a few things I'd
be asking myself and trying:

1. Are you using FileOpen on these template/documents or FileNew? If
FileOpen, does the same problem occur when you use FileNew?

2. When such a file is open, if you press Alt+F11 to go into the VBA
Editor, does the document project contain any modules, forms or similar?

3. Do these files contain any ActiveX controls (textboxes,
checkboxes...)? How about numbering?

4. If you open one of these manually, holding down SHIFT, do you still
see the message later?

5. How about if you start Word in SAFE MODE (hold down CTRL) so that no
addins (including the default normal.dot) can load?
Prior to opening a document in Microsoft Word, we make a copy (file
system copy) of a Word Template. We name the copy Document.XML. So
the origins of the document begin with a template. If I open
Document.XML (the template/document) in stand alone Word and then try
to close it, I get a popup saying "Sub or Function not defined."
However, I do not see any issues with References and cannot step into
whatever function it is complaining about. So I think that it is this
automation error that is causing the problem. I do not believe that
it is a sub or function that our team has created. I believe it is
probably one of the automatically generated Word macros (in this case,
AutoClose).

After doing some research, it seems like this problem happens when
opening templates created in prior versions of Word or if Normal.dot
is corrupt.

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

Tina

Cindy,
Some answers.

1. We use the Word object .Open command to open documents.

2. When I press Alt+F11 to go into the VBA Editor, There are no
modules, forms, etc.

3. No controls, fields, etc.

4. If I open them manually while holding down SHIFT, I DO NOT get the
message.
So does this mean it is one of the macros? If so, what do I do? I
cannot edit, delete or modify the macros. When I Alt+F8, I see all
the associated macros but I cannot go ito any of them. This is very
strange. How can I figure out what is throwing the message?

5. Safe mode still produces the problem.
 
C

Cindy M -WordMVP-

Hi Tina,
4. If I open them manually while holding down SHIFT, I DO NOT get the
message.
So does this mean it is one of the macros? If so, what do I do? I
cannot edit, delete or modify the macros. When I Alt+F8, I see all
the associated macros but I cannot go ito any of them. This is very
strange. How can I figure out what is throwing the message?
When you say you "see the associated macros", do you mean you see the
code in the modules? Or just the list of modules? Do you get any kind of
message when you try to "go into any of them"?

Are you able to right-click a module and use the Export command?

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

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