View Full Version : [SOLVED:] Word Macro asking me to save template
starfighter5
09-21-2010, 03:33 AM
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 auto close 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?
starfighter5
09-21-2010, 05:09 AM
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!
Tinbendr
09-21-2010, 07:40 AM
As a solution I have tried to add
ThisDocument.Close SaveChanges:=wdDoNotSaveChanges
Is that in the template ThisDocument?
David
starfighter5
09-21-2010, 07:44 AM
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?
fumei
09-21-2010, 08:44 AM
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.
starfighter5
09-22-2010, 01:23 AM
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
starfighter5
09-22-2010, 02:08 AM
ok, I am seeing ThisDocument now under Microsoft Word Objects in the VBA editor.
It was just me being blind :)
fumei
09-22-2010, 11:37 AM
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.
starfighter5
09-23-2010, 02:20 AM
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?
fumei
09-24-2010, 09:56 AM
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?
starfighter5
09-27-2010, 03:17 AM
I start it by launching the .dot template, I take it this is bad practice?
starfighter5
09-27-2010, 03:18 AM
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
fumei
09-27-2010, 10:22 AM
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.
starfighter5
09-28-2010, 03:25 AM
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!
fumei
09-28-2010, 01:38 PM
Yes, I think I am going to have to actually see things. I wonder why AutoClose? I rarely, if ever, use it.
fumei
10-18-2010, 12:00 PM
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.
[Close]
Public Const DottedPrecursiveFont As String = "NTPreCursiveDotted"
tempFont = DottedPrecursiveFont
[/Code]
This means:
With Selection.Font
.Name = tempFont
.Kerning = 1
End With
is the same as:
With Selection.Font
.Name = "NTPreCursiveDotted"
.Kerning = 1
End With
Yes?
OK, but you can enter ANYTHING as a .Name. It does not actually mean anything.
With Selection.Font
.Name = "Polly Woddle Doodle All The Day"
.Kerning = 1
End With
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.
starfighter5
11-01-2010, 07:50 AM
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.
fumei
11-01-2010, 09:39 AM
And I have been trying to duplicate the issue. Your file does it, but none of mine do. Hmmmm.
rruckus
11-02-2010, 12:17 PM
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.
ActiveDocument.AttachedTemplate.Saved = True
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.
fumei
11-04-2010, 02:10 PM
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.
starfighter5
11-10-2010, 04:35 AM
I have come to the same conclusion, the selecting of any of the menu options changes the template which is causing the prompt.
My idea for a solution is to add the command....
ActiveDocument.AttachedTemplate.Saved = True
I am trying to test with the first menu option to see if I can get it to stop prompting.....
starfighter5
11-10-2010, 04:49 AM
I think I have narrowed the section down to ....
Set mtemp = cbCursiveMenuBar.Controls.Add(Type:=msoControlButton)
mtemp.Visible = False
mtemp.Style = msoButtonCaption
mtemp.caption = MENU_CURSIVE_CAPTION
mtemp.OnAction = "setFontToCursive"
mtemp.BeginGroup = True
Am I on the right track?
starfighter5
11-10-2010, 09:03 AM
I think I have solved it...
I added ActiveDocument.AttachedTemplate.Saved True to each of the menu entries and it now seems to be saving without prompting to save the template.
Thanks to everyone for all of the help!
fumei
11-10-2010, 11:47 AM
Yes. Either that or remove the changes to the menu before doing a save. Although I suspect that would still register as a change to the template, thus getting the request to save the template anyway.
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.