PDA

View Full Version : Saving changes to building blocks stored in a global template



Jfp87
09-25-2017, 02:48 AM
Guys,

As part of my template addin (MyTemplateAddin.dotm), Building Blocks are modified in the template itself. Is there any way I can suppress the following message when closing word:

"You have modified styles, building blocks (such as cover pages or headers) or other content that is stored in MyTemplateAddin.dotm........"

Any modification to the Building Blocks needs to be stored, which I can force using:


Sub AutoExit()
With Templates(ThisDocument.FullName)
.Saved = True
.Save
End With
End Sub

Ideally though, I would like to suppress the prompt above. Any ideas or workarounds?

Joe

Bob Phillips
09-25-2017, 02:54 AM
Use


Application.DisplayAlerts = wdAlertsNone

gmayor
09-25-2017, 03:29 AM
If you set the Saved flag to true then the subsequent Save command doesn't do anything. Why are you setting that flag to true?
If you are making changes to the template then call the following function to save the template when you have changed it. The exit macro is then superfluous.


Sub UpdateTemplate()
'Graham Mayor - http://www.gmayor.com
Dim bBackup As Boolean
bBackup = Options.CreateBackup
Options.CreateBackup = False
ThisDocument.Save
Options.CreateBackup = bBackup
lbl_Exit:
Exit Sub
End Sub

Jfp87
09-25-2017, 04:06 AM
xld,

That doesn't work for me. I still get the prompt.


Graham,

The saved flag should have been taken out, I was testing it out to see if it made any difference. Even with .Saved = True, the .Save command still saves the changes (for me anyway).

Thanks for the UpdateTemplate macro, that works for me. Could that code be placed in the exit macro so that it is only needed once, as opposed to every time the template is altered?

Joe

gmayor
09-25-2017, 06:50 AM
Add the following macro to the ThisDocument module of the template


Private Sub Document_Close()
UpdateTemplate
End Sub