Results 1 to 5 of 5
  1. #1
    4 Star Lounger
    Join Date
    Aug 2003
    Location
    Stroud, United Kingdom
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Load / Unload template (XP)

    Hello all.

    I am using a template document to supply various VB Macros and Forms that are helpful to the tasks we are performing currently in Word.
    I have placed this .dot file in the startup folder so it loads on startup etc. All this has been working fine.

    Recently I have amended the code so that various controls on the commandbar supplied by this template are either enabled or disabled depening on which macros have and haven't been run yet, to help the workflow for the user etc.

    The problem I get is that at the end of the Word session I am asked if I want to save changes to my template file, which I dont. This is only because the commandbar's settings are different on exit to what they are on startup.

    I have tried placing VB to clear this up in the 'This Document' Open and Close Methods, but these only trigger if I actually open the template, not if i open the other documents...(grrr!)

    Is there anyway of telling the template to execute code on the loading and especially unloading of itself to enable me to clear up the changes in the commandbar so users wont get the 'save changes' dialog?

    <img src=/S/coffeetime.gif border=0 alt=coffeetime width=32 height=48>

    Hopeful...
    Thanks,

    pmatz

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

    Re: Load / Unload template (XP)

    Tell Word that the template doesn't need to be saved after manipulating the commandbars:

    ThisDocument.Saved = True

  3. #3
    4 Star Lounger
    Join Date
    Aug 2003
    Location
    Stroud, United Kingdom
    Posts
    548
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Load / Unload template (XP)

    Thanks! That works ( never doubted u for a minute Hans [img]/forums/images/smilies/wink.gif[/img]

    How come it only tells Word that the template document doesnt need saving, but this doesnt affect the documents i am working on?

    Is 'ThisDocument' referring to the specific document that the VB Modules are in? As opposed to ActiveDocument etc?

    thanx agin
    Thanks,

    pmatz

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

    Re: Load / Unload template (XP)

    Yes, ThisDocument refers to the document or template that is running the code. You could also use MacroContainer for the same purpose.

    So say you have a template MyCode.dot, and it runs code that affects the active document MyLetter.doc. In the code, ActiveDocument will refer to MyLetter.Doc, but ThisDocument or MacroContainer will refer to MyCode.dot.

  5. #5
    4 Star Lounger
    Join Date
    Dec 2003
    Location
    Zoetermeer, Zuid-Holland, Netherlands
    Posts
    559
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Load / Unload template (XP)

    In addition, consider this situation:
    - global template Code.dot in the Word startup folder
    - document MyDoc.doc based on template MyDoc.dot
    - MyDoc.dot contains only lay-out and text, no code at all
    - MyDoc.dot contains a Commandbar with buttons that trigger code in Code.dot, enabling/disabling buttons on that Commandbar

    In that case you could use ActiveDocument.AttachedTemplate.Saved = True

Posting Permissions

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