VERSION 1.0 CLASS BEGIN MultiUse = -1 'True Persistable = 0 'NotPersistable DataBindingBehavior = 0 'vbNone DataSourceBehavior = 0 'vbNone MTSTransactionMode = 0 'NotAnMTSObject END Attribute VB_Name = "TemplateInfo" Attribute VB_GlobalNameSpace = False Attribute VB_Creatable = False Attribute VB_PredeclaredId = False Attribute VB_Exposed = False Option Explicit ' Save info about template customization - stuff which is modified by adding new ' menus etc. Dim bInitialized As Boolean Dim bNormalSaved As Boolean Dim bTemplateSaved As Boolean Dim bAttachedTemplateSaved As Boolean Dim m_App As Object Dim m_OfficeApp As OfficeApp Dim OldCC As Object Private Sub Class_Initialize() bInitialized = False End Sub Sub SaveContext(App As Object, OApp As OfficeApp) Dim T As Tracker: Set T = GStackTrace.Enter(TypeName(Me), "SaveContext") Dim CurrDoc As Word.Document If OApp.IsWord() Then bInitialized = True Set m_App = App Set m_OfficeApp = OApp ' Don't want to be prompted to saved Normal.dot all the time - reset at end bNormalSaved = m_App.NormalTemplate.Saved If Not m_OfficeApp.NoCurrDoc() Then Set CurrDoc = m_OfficeApp.GetActiveDocument If CurrDoc.Type = wdTypeTemplate Then bTemplateSaved = CurrDoc.Saved ElseIf CurrDoc.Type = wdTypeDocument Then If CurrDoc.AttachedTemplate.Name <> "Normal.dot" Then Set OldCC = CustomizationContext CustomizationContext = m_App.NormalTemplate bAttachedTemplateSaved = CurrDoc.AttachedTemplate.Saved Debug.Print "SaveContext - attached:", bAttachedTemplateSaved End If End If End If End If End Sub Public Sub RestoreContext() Dim T As Tracker: Set T = GStackTrace.Enter(TypeName(Me), "RestoreContext") Dim CurrDoc As Word.Document If bInitialized Then m_App.NormalTemplate.Saved = bNormalSaved If Not m_OfficeApp.NoCurrDoc() Then Set CurrDoc = m_OfficeApp.GetActiveDocument If CurrDoc.Type = wdTypeTemplate Then CurrDoc.Saved = bTemplateSaved ElseIf CurrDoc.Type = wdTypeDocument Then If CurrDoc.AttachedTemplate.Name <> "Normal.dot" Then Debug.Print "RestoreContext - attached old/new:", CurrDoc.AttachedTemplate.Saved, bAttachedTemplateSaved CurrDoc.AttachedTemplate.Saved = bAttachedTemplateSaved CustomizationContext = OldCC End If End If End If End If End Sub