Page 1 of 2 12 LastLast
Results 1 to 15 of 24
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Wait until Startup template is loaded (Word97 +)

    <P ID="edit" class=small>(Edited by chrisgreaves on 23-Nov-06 11:47. Added "later")</P>I am thwarted by a sequence of Startup templates and can't believe this hasn't tripped me up before. As well I find no reference to this problem in the VBA forum, so perhaps my terminology is strange.

    I have sixteen templates in my Startup folder. All 16 load well, and have been in place for many many months. One template holds a macro that will re-arrange toolbars on the screen "BestFitToolbarsByName", a work of art if I say so myself.

    Today I decided that it would make sense to call this macro from Normal.dot when Word was loaded, so into Normal.dot's AutoExec macro I placed the following code, reasoning that "run" was better than "call" since I didn't want any references to templates from my Normal.dot:<pre>Application.Run MacroName:="BestFitToolbarsByName"</pre>


    I receive a run-time error '80020003 Unable to run the specified macro', no doubt because at the time Normal.dot is loaded and its AutoExec fires, the target template ("Under.dot") is not available, so "BestFitToolbarsByName" is not available.

    Short of a delay tactic, such as OnTime or similar, I can't think of a logical way to delay invocation of a macro until the template is loaded; looping until a specified template is loaded places a dependency on that template, and that dependency must be coded in Normal.dot, and that, to me, is as bad as a Tools, Reference to the template.

    I know that I *am* dependant on Under.dot; I'd rather find a way of not calling it until after it is loaded.

    I know that someone will suggest On Error, if only because I hate that with a passion, but On Error seems to fall into the category of OnTime, that is, it doesn't use the sequence of loading to delay the call until the appropriate time.


    (later) I did implement the OnTime solution and it works. It's a tad disconcerting to see the screen shift after 30 seconds, just as I'm about to lay fingertips to keyboard, but it does work.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Wait until Startup template is loaded (Word97 +)

    Why don't you call BestFitToolbarsByName from an AutoExec macro in the template that contains BestFitToolbarsByName?

  3. #3
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wait until Startup template is loaded (Word97

    > AutoExec macro in the template that contains BestFitToolbarsByName
    Good point, but ....
    The Under.dot that contains BestFitToolbarsByName is a collection of macros that can be run at the user's discretion, on demand.
    Supose a user didn't want their toolbars re-arranged by name? They'd be quite annoyed if the toolbars got arranged because I thought they should be re-arranged.

    In the general case, I have a toolbar with utility macros. Some of those macros may make sense to be autorun, but only for some users.
    A macro "CloseAlltakeNoprisoners" closes all open documents without saving; it's a desperate "get rid of all this nonsense that got left on my screen" thing.
    A user may want to start Word with NO documents open, in which case a call to "CloseAlltakeNoprisoners" from that user's Normal.dot AutoExec would make sense - it would close the traditional Document1 with no further ado; however most users might want to see that Document1 sitting there and would not want an automatic call.

    This is part of what's puzzling me.
    I can't be the first user to elect to run a macro automatically at Word-load time, when the macro is in a Startup template.
    Surely?

    Supose you had d/l my Under.dot and installed it, using it quite happily as occasion demanded. Would you be happy if the next release suddenly took over your system? <font color=448800>(perhaps we should move to the Vista forum?)</font color=448800>

  4. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Wait until Startup template is loaded (Word97

    I understand why you don't want to run the macro unconditionally.
    You could make execution from AutoExec dependent on a user preference, for example a registry setting. The default (if the setting is not present) should obviously be *not* to run the macro.

  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wait until Startup template is loaded (Word97

    > The default (if the setting is not present) should obviously be *not* to run the macro.

    I'm going to sound horribly negative shortly, and I hate that.
    Your suggestion is valid and would work as well as the OnTime method, I guess.
    I'll have to mull over this.
    I'm not enamoured of going back and inserting a registry test in each of, say, 600 macros in one template alone.
    Also I was thinking more of an "opt-in" solution, from my (I'm an end-user) end rather than from the developer's end.

    The registry solution would work.
    I think I should do some more research on the sequence of loading events.
    Even having each template set a switch (registry, INI etc) when it is loaded would allow my Normal.dot to test the switch - but then I'm right back at executing some kind of loop until the switch is set.

  6. #6
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Wait until Startup template is loaded (Word97 +)

    Hi Chris
    Apologies if this seems naive, But it's my understanding that auto macros are run in the following order on launch:
    <UL><LI>Those within Normal.dot, then
    <LI>other global templates in reverse alphabetical order.[/list] Consequently, you should be able to use a msgBox response in an auto macro, within an appropriately named template to achieve the desired results.
    Regards
    Don

  7. #7
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wait until Startup template is loaded (Word97

    > Apologies if this seems naive
    Not to me. I don't even know what "naive" means (grin!)

    > Those within Normal.dot, then
    OK. This is why my Normal.dot AutoExec fails when it tries to run a macro in a Global template Under.dot.
    Normal.dot is loaded THEN the AutoExec is run BUT Under.dot is not yet loaded, so it fails.

    > use a msgBox response in an auto macro,
    This I'm, not sure of. (It is late at night for me)
    A MsgBox suggest user intervention, and I wanted to avoid any user action - I wanted to avoid having to click the toolbar button; that's why I wanted to run the Under.dot macro from an AutoExec.

    > appropriately named template
    I think that this suggests I write a template called ZZZZZZZ.dot or similar and pray that noone comes up with ZZZZZZZZZZZZZZZZZ.dot. An AutoExec macro in ZZZZZZZ.dot would then do the trick.

    (wanders off to try it)

    Nope! The ZZZZZer AutoExec macro executes BEFORE the Under.dot is loaded.
    At least, I see the (debugging) MsgBox pop up from ZZZZer before most of the toolbars (from the other 16 Startup templates) are displayed. This may mean that ZZZZer was loaded before Under.dot, or it may mean that the AutoExecs get run before the templates are released for general use.

  8. #8
    Silver Lounger
    Join Date
    Jul 2001
    Location
    Ottawa, Ontario, Canada
    Posts
    1,609
    Thanks
    0
    Thanked 1 Time in 1 Post

    Re: Wait until Startup template is loaded (Word97

    Chris
    <hr>other global templates in reverse alphabetical order.

    <hr>
    Regards
    Don

  9. #9
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wait until Startup template is loaded (Word97

    > in reverse alphabetical order.
    >> <font color=448800>(It is late at night for me)</font color=448800>

    COOL!

    I'm going to bed a very contented little camper.

    Thanks Don.

    This is, I think, a general solution to the problem.
    One writes a template "A.dot" (instead of "ZZZZZZZ.dot") which has an AutoExec macro to run any manual macro in any of the other global templates.

  10. #10
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Weert, Limburg, Netherlands
    Posts
    4,812
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wait until Startup template is loaded (Word97

    Or you write a class module in normal.dot, with application events in it, which monitors the opening of documents. Then if a doc named "under.dot" is opened, it takes appropriate action.
    Jan Karel Pieterse
    Microsoft Excel MVP, WMVP
    www.jkp-ads.com
    Professional Office Developers Association

  11. #11
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wait until Startup template is loaded (Word97

    My approach has been to not rely on code in templates, instead I put all code in DLLs.
    For example, the following is ALL the code in my Normal template for Word 2000, Word 2002, and Word 2003.
    And, I have something similar for Word 97.
    <code>
    Option Explicit
    Public clsWordVBNormal As WordVBNormal

    Public Sub AutoClose()
    SetupClass
    clsWordVBNormal.clsAutoClose
    End Sub

    Public Sub AutoExec()
    SetupClass
    End Sub

    Public Sub AutoExit()
    SetupClass
    clsWordVBNormal.clsAutoExit
    End Sub

    Public Sub AutoNew()
    SetupClass
    End Sub

    Public Sub AutoOpen()
    SetupClass
    End Sub

    Public Sub ResetToolsOptionsView()
    SetupClass
    clsWordVBNormal.clsResetToolsOptionsView ActiveDocument
    End Sub

    Private Sub SetupClass()
    If TypeName(clsWordVBNormal) <> "WordVBNormal" Then
    Set clsWordVBNormal = New WordVBNormal
    clsWordVBNormal.SetClass Application
    End If
    End Sub
    </code>

  12. #12
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wait until Startup template is loaded (Word97

    > Or you write a class module in normal.dot,
    Thanks, Jan. I like this. It lends itself very nicely to some sort of session variable, holding a list of templates and macros.
    ",under.dot,BestFitToolBarsByName,under.dot,OpenRe cent,bilt,reportBilling.

    Not only that, but it would make a nice little training exercise for class, too!

  13. #13
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wait until Startup template is loaded (Word97

    >Then the AutoExec macro in Under.dot could look like this:
    Steve, thanks for this, but the solution has to lie in the hands of the user (in this case I am both the user and the developer).
    For example, how, as a user, would you automate the run of a macro supplied by a third party? You don't have access to the third-party template source code; the project is locked.

  14. #14
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wait until Startup template is loaded (Word97

    > instead I put all code in DLLs.
    Howard, thanks for the response.
    I tried dLLs about seven years ago and got fed up with having to re-register DLLs in locked tempaltes that made use of them. Perhaps the situation has changed.
    How would you advise an end-user to go about writing a DLL to automate running BestFitToolbarsByName from my (locked) Under.dot?

    I think that the general problem here is "running a macro in another template (once the template is available) from Normal.dot".

  15. #15
    Gold Lounger
    Join Date
    Dec 2000
    Location
    New Hampshire, USA
    Posts
    3,386
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Wait until Startup template is loaded (Word97

    i use dlls with locked templates.
    just make sure that the reregistration occurs while the template is not in use.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •