Log in

View Full Version : Solved: Do you want to save changes to document template?



Sirfanta
08-16-2007, 02:13 AM
Hi
I have a template that starts a macro. Is there a way to disable this question?
“Do you want to save changes to document template?”
The templates are never going to be altered by the user.
Why does the question appear?

lucas
08-16-2007, 06:43 AM
Is the macro run from document_new or document_open?

Sirfanta
08-16-2007, 07:23 AM
Im use`ing autonew (name of the module)

vksingh24
08-16-2007, 11:40 PM
You must be making changes into your template, through your code. Otherwise there is no way you can get this options.

Sirfanta
08-17-2007, 12:47 AM
Here is a sample; this is not the document I?m working on! :)
Open the template, save the new doc. ?Do you want to save changes to document template?? :think:

lucas
08-17-2007, 06:35 AM
Hi Sirfanta,
I think the biggest problem was the toolbar...you will have to find a different way to do that...

I changed some other things and added option explicit to your code modules....let me know what you think.

I changed your autonew module to main and put your autorun code in thisworkbook module in document new procedure..

Sirfanta
08-19-2007, 11:53 PM
Thank you for the reply Lucas. :beerchug:
It was the toolbar that makes the question to appear. But what?s wrong whit my code? :dunno
I need the toolbar, In my project I have 7buttons on the toolbar.
So is there a better way to do this? :think:

geekgirlau
08-20-2007, 05:30 PM
Correct me if I'm wrong, but if the toolbar is created within the template, it should be displayed as soon as the template is opened - you shouldn't need to create it again each time.

Sirfanta
08-20-2007, 11:30 PM
Thank for replying geekgirlau :hi:
In a perfect world the toolbar shouldn?t need to be created more than once.
But if the user closes the toolbar, the toolbar is gone.

I have a button in the document that the user can press to open the toolbar.
I also have a toolbar that open?s if the user press a button in the first toolbar (I like toolbars :P) Is there a code that I can put in ?BeforeSave()? that disables save to template? The user should never have the opportunity to save to template.

geekgirlau
08-20-2007, 11:37 PM
I think you'll find that if the user closes the toolbar, it is not displayed but it has not been deleted. Perhaps all you need here is to make sure that the toolbar is attached to your template, and that your code makes it visible.

The other option is to set the Saved property of the template as True. Word will assume that it doesn't need to save it and no prompt will appear.

Sirfanta
08-20-2007, 11:52 PM
I appreciate that you take time to reply geekgirlau :)
That?s true, I don?t need to delete it ;) . when you say attached, isn?t that what im doing? (if I just delete the delete toolbar part)


How to set the ?saved property of the template as True??

geekgirlau
08-21-2007, 12:09 AM
I would suggest you try the following:

Open the template and create the toolbar manually - make sure the toolbar is attached to your template, and not normal.dot or another document.
In the Document New event, make the toolbar visibleTry this first to see if it works.

Off the top of my head, I'm not sure exactly what to do with the saved property. For the active document, you would just do

ActiveDocument.Saved = True

but I suspect with the template you may have to loop through all the templates and add-ins, check for the name of your template, then set that value to true.

Anne Troy
08-21-2007, 07:56 PM
The other option is to set the Saved property of the template as True. Word will assume that it doesn't need to save it and no prompt will appear.

...as shown here under the Private Sub Document Close...
http://vbaexpress.com/kb/getarticle.php?kb_id=14

Private Sub Document_Close()

'This closes the Templates toolbar when the
'document is closed. It also keeps the user from
'changing the template. This is what we call an *on-event*
'procedure (macro) because it is
'run when the document is closed.

On Error Resume Next
CommandBars("Menu Bar").Controls("Te&mplates").Delete
ActiveDocument.AttachedTemplate.Saved = True

End Sub


(Hi, girl!)

geekgirlau
08-21-2007, 10:53 PM
Nice to hear from you Dreamboat!

Sirfanta
08-22-2007, 12:56 AM
Nice! :beerchug:
ActiveDocument.AttachedTemplate.Saved = True


Works like a charm :bow:

Thank You Anne Troy and Geekgirlau :kiss