View Single Post
 
Old 10-17-2015, 10:31 PM
macropod's Avatar
macropod macropod is offline Windows 7 64bit Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 21,963
macropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond reputemacropod has a reputation beyond repute
Default

Well, testing and reporting whether a variable/property stored in a document is the same as the one stored in the attached template is easy enough, but I'm not sure what that achieves - it may actually provide false comfort.

Having said that, if you still want to go down that path, you could open the template for editing and set it's version with code like:
Code:
Sub SetTemplateVersion()
Dim SngVer As Single
With ActiveDocument
  On Error GoTo ErrExit
  If .Variables("TemplateVersion") Is Nothing Then
    SngVer = InputBox(Prompt:="Please input the Template Version #", _
      Title:="Template Version Input", Default:="1.0")
    .Variables.Add Name:="TemplateVersion", Value:=SngVer
  Else
    SngVer = InputBox(Prompt:="Please input the Template Version #", _
      Title:="Template Version Input", Default:=Format(.Variables("TemplateVersion").Value, "0.0"))
    .Variables("TemplateVersion").Value = SngVer
  End If
  MsgBox "The Template Version has been set to: " & Format(.Variables("TemplateVersion").Value, "0.0")
  .Save
End With
ErrExit:
End Sub
You could leave that code stored in the template for ease of future use. Having stored it in the template, you could also run it against any existing documents based on the template to set their template version #s (assuming you know them). Then, to do a version check with any document based on the template when the document is opened, you could add the following code to the template's 'ThisDocument' code module:
Code:
Private Sub Document_Open()
Application.ScreenUpdating = False
Dim Tmplt As Document, SngVer As Single, StrMsg As String
With ActiveDocument
  Set Tmplt = .AttachedTemplate.OpenAsDocument
  With Tmplt
    On Error Resume Next
    SngVer = .Variables("TemplateVersion").Value
    On Error GoTo 0
    .Close False
  End With
  If .Variables("TemplateVersion") Is Nothing Then
    StrMsg = "This Document has no record of its Template Version."
  ElseIf .Variables("TemplateVersion").Value <> SngVer Then
    StrMsg = "This Document is based on Template Version: " & Format(.Variables("TemplateVersion").Value, "0.0")
  End If
  MsgBox StrMsg & vbCr & "The Current Template Version is: " & Format(SngVer, "0.0")
End With
Application.ScreenUpdating = True
End Sub
__________________
Cheers,
Paul Edstein
[Fmr MS MVP - Word]
Reply With Quote