• Where’s my included code? (Word 97 SR2)

    Home » Forums » AskWoody support » Productivity software by function » MS Word and word processing help » Where’s my included code? (Word 97 SR2)

    Author
    Topic
    #358680

    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.

    Viewing 4 reply threads
    Author
    Replies
    • #535685

      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: Template Basics (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.

      • #535714

        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?

        • #535762

          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.

          • #535941

            Well, PHOOEY, now it abends. I have renamed the AutoNew to GetTheAddIn, called that from AutoNew and also from the new AutoOpen. I can create a new template from this template (was SUPPOSED to be my standard starter template), but when I based a new document on the second template, it abended. Three times.

            I didn’t think that had anything to do with this thread but when I deleted the AutoOpen and saved the second template with a new name, I WAS able to base a new document on it and did not get the abend. Now I’ve opened the second template without the AutoOpen, ADDED the AutoOpen and saved it with a different name. I WAS ABLE to base a new document on it and re-open that document (closing Word each time). The toolbar is there so the AutoOpen works. The template with the AutoOpen works; there’s just something flaky about it that will embarrass me by abending on my co-workers at inopportune times. Still phooey.

            Have a nice weekend all. We have Monday off (BC Day).

      • #535717

        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.

    • #535748

      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

      • #535753

        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.

        • #535758

          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 ) – 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

          • #535857

            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.

    • #535859

      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.

    • #535871

      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.

      • #535976

        Some things I know about global templates.

        We are not talking about Normal.dot which is both a global template and a document template and some other things besides.

        A global template is one that holds customizations including menus, toolbars, macros and keybindings that are then available to any open document. A global template is not used as the template from which a document is started.

        A global template can be kept anywhere within the computer system including on the network. A global template should not be kept in the templates folder (user or workgroup) or any subfolders of the templates folder.

        If a template is loaded as a global template, it will react to document and application events if those are coded into the global template. An AutoOpen procedure in a global template will be used when you open the template. It will not be used automatically when any other document is opened. An AutoNew procedure in a global template will be used when you create a new document based on the global template, which you should not be doing.

        If you code a global template for DocumentOpen, DocumentChange, etc. that code will respond to those events in your other documents. The global template does not need to be attached, it needs to be loaded into memory.

        One way to load a template as a global is to put the template or a shortcut to that template into the user’s Word Startup folder. If you do that, it becomes global the next time that the user starts Word.

        If you share a global template on a network so that multiple people have it loaded at the same time, you cannot revise the template unless all of those people close Word, at the same time.

        You can use a macro in a document template to load a different template as a global. It sounds as if that is what you have been doing. This is definitely doing it the hard way, but you can do it. Anytime the global template is moved or renamed, you can then modify the code in all of your document templates that call it.

        A gentler way would be to have one small global template that contains the macros to load other global templates as needed. Have that small global template loaded automatically. Have your document templates call those macros when they need procedures or customizations that are contained in the larger or specialized global templates.

        It is one thing to load a global template using a macro. It is another thing to unload it. While this can be done easily, can you be sure that it is the right thing to be doing. What if while editing documentA which loads GlobalX, your user edits or creates documentB which also requires GlobalX. You want to make sure that your load macro checks to see if GlobalX is already loaded (or otherwise your user will get a cute little error message in the middle of the screen). But then when you close documentA, do you want to unload GlobalX? If you do, then what happens to documentB?

        • #536404

          Thanks for all the advice, Charles. I have two questions.

          When you say “A gentler way would be to have one small global template that contains the macros to load other global templates as needed. Have that small global template loaded automatically”, what does “loaded automatically” mean? I do not think I can take a solution that involves making a change or installation on other people’s computers. How else do you load a global template automatically?

          You mentioned in this and your other note that a global template should not be kept in the Workgroup Templates folder. Why is that?

    • #535899

      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.

      • #535977

        Suggestion:

        Put the template on the LAN – not in the workgroup templates folder, though!

        In the users’ network login script, have a procedure that copies that file to the user’s startup directory if the template on the LAN is newer than the one on the local computer. For laptops, etc. when they are not logged into the network it will still be available to them.

        Idea 2) for the laptop users, have the login script do the same with the other workgroup templates, copying them to a local folder (not in the user templates folder) and have the startup for the laptop as a standalone map that folder that the workgroup templates folder will appear to Word to be in the same place.

    Viewing 4 reply threads
    Reply To: Reply #536404 in Where’s my included code? (Word 97 SR2)

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

    Your information:




    Cancel