Consulting

Page 1 of 2 1 2 LastLast
Results 1 to 20 of 24

Thread: Word Macro asking me to save template

  1. #1

    Word Macro asking me to save template

    I am trying to update a macro that was originally written to run on Windows XP machines to make it compatible with Windows 7.

    My original issue was allowing the macro to run from the c:\Program Files\Macro folder instead of the users Windows 7 folder.

    That has now been resolved and everything is working apart from the following issue....

    Everytime I exit it asks me

    'Do you also want to save changes to the document template?'

    As a solution I have tried to add

    ThisDocument.Close SaveChanges:=wdDoNotSaveChanges
    to the autoclose but this has still not resolved the issue.

    I am trying to adapt code that somebody else has originally written so I may be missing something, can anyone suggest anything?

  2. #2
    Thought I would clarify a little....

    The macro creates a toolbar
    If you select any of the options in the toolbar and then try and save to document it asks you if you want to save the template

    Hope this makes things a little clearer!

  3. #3
    VBAX Expert Tinbendr's Avatar
    Joined
    Jun 2005
    Location
    North Central Mississippi (The Pines)
    Posts
    993
    Location
    As a solution I have tried to add

    [vba]ThisDocument.Close SaveChanges:=wdDoNotSaveChanges[/vba]
    Is that in the template ThisDocument?

    David

  4. #4
    Hi,

    I have searched the whole project and ThisDocument is not present, I guess that answers the question of why it is having no effect

    The error is happening when I am saving, not neccesarily when I am closing. With this is mind, should the AutoClose be where I should be focusing my attention?

  5. #5
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    1. "I have searched the whole project and ThisDocument is not present"

    This is simply not possible. ALL Word projects have a ThisDocument. All of them.

    2. Some clarification is needed. Please describe precisely the actions to get the document. Is this a document cloned from a template? Is it in fact a real template being used?

    If it is a document properly cloned from a template, then ThisDocument is an action on THAT document...not the template.

    3. If it is a real template, are you actually opening it? If so, do not do that. Template should never be opend (if they are being used properly).

    Essentially though we need to know what you are doing. Perhaps posting the actual code may help.

  6. #6
    Hi fumei,

    These are the steps I take to get to the document.....

    1 - Launch the .dot template
    2 - This loads Microsoft Word and launches the toolbar and gives me a new document
    3 - I can type away and select items from the toolbar
    4 - If I then save the document this works fine
    5 - Then after saving, it asks me to save the template

    I was trying to avoid posting the code as it is a commercial product, I am a long suffering technician who has been tasked with updating it to work with windows 7. Do you have an email address or can you PM me with one? I could email it over to you, just wanted to avoid posting it up if at all possible.

    Thanks for all your help

  7. #7
    ok, I am seeing ThisDocument now under Microsoft Word Objects in the VBA editor.

    It was just me being blind

  8. #8
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    I can not seem to PM you. Can you PM me? Oh...what version of Word? If it is 2007 or 2010, then I am sorry but I probably can not help.

    BTW: I am curious. Why is there an issue regarding Windows 7?

    Oh, and:

    1 - Launch the .dot template
    2 - This loads Microsoft Word and launches the toolbar and gives me a new document

    Please elaborate. Launch...how precisely?

    And why do you put "launches the toolbar" BEFORE "gives me a new document"? I do not really know what you mean by "launches the toolbar". Toolbars are not launched.

  9. #9
    I have posted the Autoclose code to pastebin as that section is where I made a change too

    http://pastebin.com/YME1D9gf

    I'm sorry I can't be anymore specific, i'm not that experienced with VB and am trying to learn as quick as I can!

    Can you spot anything in the code I have posted?

  10. #10
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Are you using Option Explicit? Your code has a few instructions that appear to point to procedures that are not declared or available. For example:

    createDeactivatedFontMenu
    activateNTF

    Please answer the questions. How are you starting this?

  11. #11
    I start it by launching the .dot template, I take it this is bad practice?

  12. #12
    Sorry, I should clarify....

    I load the .dot template by double clicking it which launches Word
    I am then presented with a blank document and the templates toolbar

  13. #13
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Please answer questions asked of you.

    1. Are you using Option Explicit?

    2. the code you posted, where - exactly - is it? Is it in the .dot file (the template)?

    3. "The macro creates a toolbar" WHAT macro????? Is it something in:
    createDeactivatedFontMenu, or activateNTF? If so, it may help to see what those do.

    In any case, it is likely the issue of "create a toolbar". Why are you doing that?

    If a toolbar is created then you are, in fact, potentially changing the template. So Word politely asks if you want to save the change to the template file.

    Why not simply have the toolbar in the template? This issue would not happen.

  14. #14
    1 - I have searched the project and can find several instances of OptionExplicit so I guess the answer is yes to that one

    2 - The code I have posted is from the AutoClose Macro

    3 - Sorry, I have been getting myself confused. The Template file contains the macros, I understand this now! The macro activateNTF appears to create the toolbar.

    As I know have the grand total of 10 posts I should be able to PM you so I will send the .dot over if that would make things easier

    Thanks for sticking with this one!

  15. #15
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    Yes, I think I am going to have to actually see things. I wonder why AutoClose? I rarely, if ever, use it.

  16. #16
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    BUMP.

    OK, I have th efile and I am working on this. The template has a menu with what appears to be actions that create manually formatted (but via code) text. This creates those phony "styles" - Yadda + parameters.

    I always thought this was a BAD thing for Word to do. They are listed under the Styles dropdown, but they are NOT styles. It seems the creation of these is making Word think the template (.dot) file has been altered.

    There are some very strange things, and I am still looking. I would like to point some points though.
    [vba]
    Public Const DottedPrecursiveFont As String = "NTPreCursiveDotted"

    tempFont = DottedPrecursiveFont
    [/vba]
    This means:[vba]
    With Selection.Font
    .Name = tempFont
    .Kerning = 1
    End With
    [/vba]is the same as:

    With Selection.Font
    .Name = "NTPreCursiveDotted"
    .Kerning = 1
    End With
    [/vba]Yes?

    OK, but you can enter ANYTHING as a .Name. It does not actually mean anything.
    [vba]
    With Selection.Font
    .Name = "Polly Woddle Doodle All The Day"
    .Kerning = 1
    End With
    [/vba]is perfectly legitimate. It is NOT an error. Try it. What it does is put

    Polly Woddle Doodle All The Day

    as one of those "styles" in the dropdown. That is the ONLY thing it does.

    I am still trying to duplicate the issue (getting the save the template question) with a much simpler template.

  17. #17
    I have been messing with this all week and to be honest don't seem to be getting anywhere

    I think I am trying to supress the error message which is the wrong approach.

  18. #18
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    And I have been trying to duplicate the issue. Your file does it, but none of mine do. Hmmmm.

  19. #19
    VBAX Regular
    Joined
    Oct 2010
    Posts
    66
    Location
    I've run into this problem too. I don't have a great solution, but the problem is definitely related to a piece of code that you are running that alters the attached template. So you should first track down any code that works with the template (building blocks, styles, etc) and make sure it's not altering anything in the attached template. Sometimes you wont realize you are changing something, but you usualy are whenevr you work with those objects.

    If you can't change your code to remove those items, try putting the following line right after your code that interacts with the attached template.

    [VBA]
    ActiveDocument.AttachedTemplate.Saved = True

    [/VBA]

    It tells Word that the attached template is already saved so Word won't prompt the user again. You can even put this line in the doc before save event and doc close event as a catch all.

  20. #20
    VBAX Wizard
    Joined
    May 2004
    Posts
    6,713
    Location
    I am fairly sure the change is the adding of the check mark to your menu. The menu starts with NO check marks, but if you select one of the items, a check mark is added. Thus, this IS a change to something that belongs to the template - the menu.

Posting Permissions

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