Page 1 of 2 12 LastLast
Results 1 to 15 of 20
  1. #1
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Vancouver, BC
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Where's my included code? (Word 97 SR2)

    I created template1 that has an AutoNew macro that adds in code from a common template. The common template does the real work, setting some fields, and it has a toolbar with style buttons.

    When the documents based on template1 are first opened, the toolbar is there, but when they are later opened, the new toolbar is not there. When I go into Tools | Macro | Macros, and look for the attached template, it is not there. But when I single click on AutoNew, the attached template gets added to the list of addins under Tools | Templates and Addins, and the
    toolbar shows up. I don't have to run or edit AutoNew; it only requires selecting it.

    Is there something I neglected to do in either template1 or the common template, or do I need an AutoOpen macro that does pretty much what the
    AutoNew does: adds in the common template? I don't want the code in the common template to execute again - I just want the toolbars available and the macros available if someone clicks on a button that invokes them. What happens when I select but not execute the AutoNew is exactly what I want to happen when the documents based on template1 are re-opened.

    What gets executed when I single click to select the AutoNew macro? Is that a simple command that I can put in an AutoOpen?

    I sure hope someone understands this.

  2. #2
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Madison, Wisconsin, Wisconsin, USA
    Posts
    1,701
    Thanks
    56
    Thanked 63 Times in 61 Posts

    Re: Where's my included code? (Word 97 SR2)

    Not sure what it is you are really trying to do . . . but . . .

    It may be that you want your resource template to be a global template. See: <A target="_blank" HREF=http://www.addbalance.com/usersguide/templates.htm> Template Basics</A> (addbalance.com/usersguide/templates.htm) for more on templates (user and workgroup), document templates, global templates and Normal.dot.

    An AutoNew macro is activated by the creation of a new document from a template containing the AutoNew macro. An AutoOpen macro is activated by the opening of an existing document based upon the template containing the AutoOpen macro. (There are more variations on this, but those are the basics.) It may be that you need an AutoOpen macro to supplement your AutoNew macro.

    Neither, routinely, transfers code to a document. A big part of the reason for templates is to have a central repository for code, toolbars, etc., rather than putting these into documents. Putting these into documents (1) increases document file size and (2) is much harder to revise.
    Charles Kyle Kenyon
    Madison, Wisconsin

  3. #3
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Vancouver, BC
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Where's my included code? (Word 97 SR2)

    When you say "A big part of the reason for templates is to have a central repository for code, toolbars, etc., rather than putting these into documents", that's what I'm trying to do. All my templates are based on a template that uses the code "'AddIns.Add FileName:=strTMCPath, Install:=True'" to add in the template that's the central repository, and I added the template to the References. I thought that would make the central repository template available to the documents based on the templates. Is that not true? In the documents, it seems I have to go into Macros and click on AutoNew to get the central repository template to activate. What am I missing?

  4. #4
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Vancouver, BC
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Where's my included code? (Word 97 SR2)

    Chas, I've now downloaded your templates document. I don't think I'll be allowed to put a shortcut to the global template in each user's Startup folder" and it certainly won't be done for us on everyone's PC. That's why I was trying via the AutoNew macro to get the global template added into the documents.

  5. #5
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 28 Times in 27 Posts

    Re: Where's my included code? (Word 97 SR2)

    Hi Wendy,

    I kinda sortof get what you're trying to do, but it's not completely clear.

    If the AutoNew macro contains code that ensures that the global template is loaded, then that is only going to run when a new document is created. Each subsequent time you open the document, the global template isn't loaded because the AutoNew event doesn't fire. So you do need to put code into an AutoOpen macro to ensure that the global template is loaded.

    If code is run from the global template, every time it is loaded, and this code is appropriate for new documents but not opening existing documents, then it just may require some rethinking as to how things get deployed. - What technique are you currently using to trigger the code in the global template to run whenever it is loaded?

    Couldn't the procedures in the global template, that support AutoNew in the individual document templates, be broken out into separate procedures? - that way, the AutoNew in the document template could contain calls to the procedures in the global template that are relevant to creating a new document. The AutoOpen then doesn't need to contain these calls, all it needs is code to ensure that the global template is loaded.

    Not sure if this helps; hope I'm understanding the situation correctly.

    Gary

  6. #6
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Vancouver, BC
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Where's my included code? (Word 97 SR2)

    Many thanks for the reply, Gary.
    What I'm calling the global template contains subroutines to toggle a watermark and update some properties fields. There's a toolbar with the watermark toggle button and with style buttons.

    I was getting confused - the autonew specifically calls the update properties subroutine that's in the global template, so that doesn't execute by itself. That complication that I threw in can be ignored.

    It sounds like you're saying I misunderstood what an addin is - it doesn't stay with the document the way a template and its macros stay with the document. It's this that I really want confirmed before I do the AutoOpen. Here I went and created this global template so I'd have to only make changes in the one place, and now I have to go and update all the templates.

    I CAN just copy the code in the AutoNew to an AutoOpen, minus the call to the properties subroutine. Or I guess, I'd have
    Sub AutoNew()
    DoTheAddIn
    DoThePropertiesSubroutine
    and
    Sub AutoOpen()
    DoTheAddIn
    and have DoTheAddIn as a subroutine. Is that what one would do?

    What triggers the AddIn to get added when I go to look at the macro without actually having to look at it? If code is required in an AutoOpen to ensure the global template is loaded, and I don't have code there, what makes it get loaded when I select but don't open the AutoNew? I don't suppose I NEED the answer to this question. Besides, in my AutoNew, I look around a few places for the AddIn (in case the user is not connected to the LAN), and before giving up ask the user where it is, so I suppose I should want to execute my code rather than have Word do something automatically.

  7. #7
    Super Moderator
    Join Date
    Dec 2000
    Location
    New York, NY
    Posts
    2,970
    Thanks
    3
    Thanked 28 Times in 27 Posts

    Re: Where's my included code? (Word 97 SR2)

    Hi again Wendy,

    The add-in "belongs" to the Word application, and not to a specific document. So once it's been loaded in the current Word session, barring intervention it should stay loaded. Presumably your code does do a test first to see if the add-in is already loaded, before trying to load it again? (what happens if you try to load via code, an add-in that is already loaded?)

    Forgot to address the other bit in my first note (which was lengthy enough <g>) - actually I don't understand why the add-in is loading just by your single-clicking on the AutoNew procedure - from where are you accessing the AutoNew procedure to click on it?

    Gary

  8. #8
    Silver Lounger Charles Kenyon's Avatar
    Join Date
    Jan 2001
    Location
    Madison, Wisconsin, Wisconsin, USA
    Posts
    1,701
    Thanks
    56
    Thanked 63 Times in 61 Posts

    Re: Where's my included code? (Word 97 SR2)

    An AutoNew macro is activated by the creation of a new document from a template containing the AutoNew macro. An AutoOpen macro is activated by the opening of an existing document based upon the template containing the AutoOpen macro. (There are more variations on this, but those are the basics.) It may be that you need an AutoOpen macro to supplement your AutoNew macro.
    Charles Kyle Kenyon
    Madison, Wisconsin

  9. #9
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Vancouver, BC
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Where's my included code? (Word 97 SR2)

    Gary, yes I am checking to see that the add-in is not already loaded. I can answer what happens if you don't - it adds it again and the list of add-ins shows it twice, or however many times you add it. You don't get an error, though.

    Re: the single clicking, when I open the document based on the template, I go into Tools | Macro | Macros. All of them are listed and I select AutoNew. Before I click a button to say whether I want to Run or Edit it or what, my toolbar from the add-in shows up. When I checked under templates and add-ins before doing that, the add-in wasn't there. After the toolbar showed up, I cancelled out of the Macros dialog and checked again - the add-in was there.

    You're right it stays loaded once it has been loaded.

  10. #10
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Vancouver, BC
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Where's my included code? (Word 97 SR2)

    BAM, these are workgroup templates. We don't get to change people's normal.dot. And the article begs the question - it talks about using an add-in. Well, I'm TRYING to.

    I'm sure the AutoOpen will work. I'm resigned to really wanting one.

  11. #11
    BAM
    Guest

    Re: Where's my included code? (Word 97 SR2)

    Hi Wendy,

    I'm not 100% sure that I follow, but if you are placing the AutoNew/AutoOpen in your global template then that is the problem. Global Auto macros function correctly if placed in Normal.dot.

    However, here is an article that contains a workaround:
    <A target="_blank" HREF=http://www.mvps.org/word/FAQs/MacrosVBA/PseudoAutoMacros.htm>http://www.mvps.org/word/FAQs/Macros...AutoMacros.htm</A>
    ~~~~~~~~~~~~
    Cheers!

  12. #12
    BAM
    Guest

    Re: Where's my included code? (Word 97 SR2)

    Hi Wendy,

    If the AutoOpen is stored in the template the document is based on then that will work.

    However if you are placing the AutoOpen in the global template then you will need to use the DocumentChange event as described in the article.
    ~~~~~~~~~~~~~
    Cheers! <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  13. #13
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Vancouver, BC
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Where's my included code? (Word 97 SR2)

    Thanks for the replies, BAM. The AutoNew IS in the template the document is based on, and now I get to update all those templates with an AutoOpen. They'll both just attach the global template.

    If I had a DocumentChange event in the global template, don't I still have the problem of attaching the global template so the document can find the DocumentChange event? Am I really missing something here?

    It's a bit confusing, my use of 'global'. It's workgroup global (meaning a template on the LAN that's used by all the templates), not Startup folder on your own computer global.

  14. #14
    BAM
    Guest

    Re: Where's my included code? (Word 97 SR2)

    Hi Wendy,

    <<It's a bit confusing, my use of 'global'. It's workgroup global (meaning a template on the LAN that's used by all the templates), not Startup folder on your own computer global.>>

    <img src=/S/bingo.gif border=0 alt=bingo width=15 height=22> Now I understand perfectly! I was thinking that you had shortcut to a template on the LAN in the Startup folder. (How 'bout we call it a macro library for clarity?) In that situation then the DocumentChange event would need to be used.

    As it is now, if the template that contains the macro library isn't loaded then no, the DocumentChange event won't really do anything.

    One other item has me puzzled, once the template for the macro library is loaded it will stay loaded until the user exits Word (unless of course you have an AutoClose macro in the template to unload the macro library template). So in that respect, why not place a shortcut to the template in the user's Startup folder or point the Startup folder to the LAN?

    Then you could use the DocumentChange event if necessary.
    ~~~~~~~~~~~~~
    Cheers! <img src=/S/smile.gif border=0 alt=smile width=15 height=15>

  15. #15
    2 Star Lounger
    Join Date
    Jan 2001
    Location
    Vancouver, BC
    Posts
    139
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Where's my included code? (Word 97 SR2)

    BAM, I can't have a solution that depends on a configuration on the user's machine. We have too many users: staff onsite, contractors onsite with laptops, contractors offsite connected to the lan or not. We keep getting new machines (poor us) and I can't even get the installation people to agree to set up the Workgroup Templates Directory. If the users are not connected to the lan, I have instructions for them to get the common macro and put it where they put the rest of our templates and when I'm trying to find it to add it in, they get to tell me where that is (this last bit would work WAY better for them if I knew how to bring up the browse dialog box and use the location they identify from the dialog).

    I like the startup folder on the LAN idea, but I still need to try to find the add-in for people not on the LAN, so I think I may as well just add it for everyone. I'll entertain rebuttals to this last thought.

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
  •