Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / October 2007

Tip: Looking for answers? Try searching our database.

Runtime 91 error for ActiveDocument in AutoExec macro

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
proashu - 14 Sep 2007 19:32 GMT
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.
Jay Freedman - 14 Sep 2007 21:43 GMT
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.

Signature

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.

> I am trying to invoke MS word in the following manner:
>
[quoted text clipped - 30 lines]
>
> If you have any ideas as to how can I avoid this, that would be great.
proashu - 01 Oct 2007 16:00 GMT
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 ?

> 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
[quoted text clipped - 40 lines]
> >
> > If you have any ideas as to how can I avoid this, that would be great.
Jay Freedman - 01 Oct 2007 16:20 GMT
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.

Signature

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.

> Thanks Jay.
>
[quoted text clipped - 69 lines]
>>> If you have any ideas as to how can I avoid this, that would be
>>> great.
proashu - 02 Oct 2007 17:15 GMT
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..

> 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
[quoted text clipped - 81 lines]
> >>> If you have any ideas as to how can I avoid this, that would be
> >>> great.
Jay Freedman - 02 Oct 2007 18:43 GMT
Sorry to say, you've gone beyond my area of knowledge. I've never had the
pleasure (!) of dealing with Acrobat and PDF Creator.

> Thanks again Jay.
>
[quoted text clipped - 113 lines]
>>>>> If you have any ideas as to how can I avoid this, that would be
>>>>> great.
Graham Mayor - 03 Oct 2007 06:17 GMT
You will find some background relating to Acrobat at
http://www.gmayor.com/lose_that_adobe_acrobat_toolbar.htm - see particularly
the section on Acrobat 7.

Signature

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor -  Word MVP

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> Thanks again Jay.
>
[quoted text clipped - 113 lines]
>>>>> If you have any ideas as to how can I avoid this, that would be
>>>>> great.
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.