Runtime 91 error for ActiveDocument in AutoExec macro

P

proashu

I am trying to invoke MS word in the following manner:

start winword.exe /lc:\glb\myglobal.dot /tc:\tmp\doctemplate.dot /

myglobal.dot -
My global template - contains the following logic
Public Sub AutoExec()
If ActiveDocument.Bookmarks.Exists("CSWB") Then If (InStr(1,
ActiveDocument.FullName, ".rtf") < 1) Then
ActiveDocument.RunAutoMacro (wdAutoNew)
End if
End If

doctemplate.dot -
A document template that contains the AutoNew macro defined.

Problem scenario:
When I run - "start winword.exe /lc:\glb\myglobal.dot
/tc:\tmp\doctemplate.dot /" from command prompt it works fine.

I install Adobe Acrobat writer on my machine, and run the same command,
It fails with a Runtime 91 error - Object variable not set
Looks like ActiveDocument object is not initialized and fails when I try to
access ActiveDocument.Bookmarks collection.

When I uninstall Adobe acrobat writer, the problem goes away.

This is happening in production as well (that actually triggered this
analysis) but I don't necessarily see Adobe writer installed in production.
Is there anything else that when installed would change the behaviour of
AutoExec as I have mentioned ?

If you have any ideas as to how can I avoid this, that would be great.
 
J

Jay Freedman

The AutoExec macro starts running as soon as Word loads, which may be before
there is any document loaded into the workspace. I'd guess that the
difference between the two situations -- working vs. failing -- may depend
on just how long it takes for the document to load, which in turn may depend
on whether an add-in like Acrobat Writer is loading first, or on whether the
document is stored locally or across the network.

You might be able to work around this with the OnTime technique in
http://word.mvps.org/faqs/userforms/AutoExecUsertFm.htm.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
P

proashu

Thanks Jay.

The additional delay of few seconds might not be desirable to our business.
This is happening over a Citrix connection, and additonal delay is not good.

My recent findings indicate that -
When I try to look at the MS Word installs for the people who are
affected by the Runtime error,

I do not see any addins in the startup folder.
I do not see any COM Addins as well.

So I am not sure what else would cause the ActiveDocument not to load
before my AutoExec logic fires off, and throw a Runtime 91 error when I
invoke ActiveDocument.bookmarks

Is there anything else that you can think of that can cause the loading of
the document to be delayed ?
 
J

Jay Freedman

I don't have any experience with Citrix, but if the connection is as slow as
your message seems to suggest, that in itself could be the cause. It might
also explain why some people see the error and others don't -- those that do
might just have a slower connection for some reason.

It might be possible in your AutoExec macro to use an On Error trap in a
loop, so that the first access to ActiveDocument is retried until it
succeeds or there have been a specified number of unsuccessful tries (or
until a specified time has elapsed). Be sure to allow some exit condition of
this sort, so the loop doesn't lock up the application for an extended
period.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
P

proashu

Thanks again Jay.

I found out that changing the loadBehaviour of the PDF Creator addin from 3
to 2 gets rid of the problem.

However when reading through the documentation (and I must say, I am a
novice in the Addins area) there was a mention of a loadBehaviour = 0 as well
as loadBehaviour = 2 that can be set.

I know that setting it to 2 makes it work (I do not see the error, as well
as the "Save as PDF" menu item), but still wanted to find out which option is
better, and why..

loadBehaviour = 0 or loadBehaviour = 2 ?

I especially don't want this to be fixed temporarily, and the error pops up
again when a tech savvy user plays around with her MS Word instance..

Any help in this regard is appreciated..

Thanks for all your advice so far..
 
J

Jay Freedman

Sorry to say, you've gone beyond my area of knowledge. I've never had the
pleasure (!) of dealing with Acrobat and PDF Creator.
 

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