• AutoExec Macro – enough to drive a person insane! (EN / MS Word 97)

    Home » Forums » AskWoody support » Productivity software by function » Visual Basic for Applications » AutoExec Macro – enough to drive a person insane! (EN / MS Word 97)

    Author
    Topic
    #373391

    Well – perhaps someone out there can explain to me the logic behind this one – or how to deal with it in any case.

    I’m working on a macro that needs to run whenever a user opens a document, or creates a new one from a template.
    The macro must run as soon as a file is opened – regardless of what the file is.
    In order to cover all possibilities, I’ve setup AutoExec, AutoNew and AutoOpen macros in a global template (globals.dot).
    For maintenance purposes, I’d like to keep the macro that is to run in a second global template (printer.dot), though
    I have also tried including it in the main global template and it makes no difference one way or the other.

    Everything functions as it should – except the AutoExec macro.

    AutoExec runs in the following situations if the Word is not already open:
    – When the user launches Word via desktop icon or start menu
    – When the user opens a document directly from Explorer
    – When the user uses the “New Office Document” shortcut under the start menu
    – When the user uses the “Open Office Document” shortcut under the start menu

    I’m aware that the AutoExec runs before any global templates are loaded by Word,
    so I use .OnTime to delay the macro for a bit.

    In each case, the macro functions as it should, EXCEPT when the user uses the
    “Open Office Document” shortcut under the start menu.

    In this case, AutoExec will run (I use a msgbox to test) , but it will not run the other macro ( contained in printers.dot).
    No error messages, no nothing. I know the script works because, as I said, if the user launches Word in any other way
    (via desktop shortcut or explorer) then the AutoExec macro does what it is supposed to. It is in this ONE scenario only
    that it decides not to cooperate.

    If anyone has an explanation for this – I’d sure appreciate hearing it.

    BTW – While troubleshooting this problem I disabled the scripts in the AutoOpen and AutoNew –
    using only a message box so I could tell what script was running when. This ruled out the possibilty
    of there being a conflict between the different auto macros.

    Viewing 0 reply threads
    Author
    Replies
    • #600434

      It’s not obvious to me how that “shortcut” works; it’s not like a normal shortcut.

      Does this workaround help: before running the macro check the .Installed property of printer.dot in the add-ins collection and, if not installed, load it before proceeding? (I think the one you want is Installed, but it might be something else… haven’t double-checked.)

      • #600580

        I checked Templates and Add-Ins and the template is installed.

        Although the “Open Office Document” shortcut initiates AutoExec, it does not execute any global macros – regardless of what I set .OnTime to. My workaround was to put the same script into the AutoNew for each template and then it will run as it should – even from this shortcut.

        I just find it odd that AutoExec will execute properly in every other situation of starting Word, except through the use of this shortcut.

        • #600646

          It is pretty odd! The shortcut runs OSA.EXE the Office Startup Application. There is some info at: http://support.microsoft.com/default.aspx?…b;en-us;Q165071 They say it initializes automation and code that is shared by the Office applications so that the applications start faster. Maybe there is some quirk in there that makes it bypass the global macros.

        • #600712

          u need to check whether the template is installed WHILE the AutoExec is running.

          One way to do this is to insert code in AutoExec to list the entire Templates collection just before you believe that the template of interest is needed.

          Using Debug.Print is best, but you could use a MsgBox to list the templates.

    Viewing 0 reply threads
    Reply To: AutoExec Macro – enough to drive a person insane! (EN / MS Word 97)

    You can use BBCodes to format your content.
    Your account can't use all available BBCodes, they will be stripped before saving.

    Your information: