Microsoft Office Forums

Go Back   Microsoft Office Forums > >

 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
  #6  
Old 10-17-2015, 10:31 PM
macropod's Avatar
macropod macropod is offline Use some sort of onload function to check whether template version uses the latest template. Windows 7 64bit Use some sort of onload function to check whether template version uses the latest template. Office 2010 32bit
Administrator
 
Join Date: Dec 2010
Location: Canberra, Australia
Posts: 22,467
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
 

Tags
macro, onload, version



Similar Threads
Thread Thread Starter Forum Replies Last Post
Template not read properly even after enabling compatible with latest version ashwini PowerPoint 1 12-17-2014 02:35 AM
Use some sort of onload function to check whether template version uses the latest template. When creating new template from established template macros getting lost. TechEd Word 3 06-09-2014 07:22 PM
Add a word 2010 function to template Esgrimidor Word VBA 4 02-23-2014 06:59 AM
Use some sort of onload function to check whether template version uses the latest template. Automatic update of links in template - closing attached template without saving stefaan Word 2 11-02-2013 07:46 AM
ActiveX controls inserted on a template do not function well ged Word 0 10-21-2010 04:53 AM

Other Forums: Access Forums

All times are GMT -7. The time now is 08:47 AM.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2025, vBulletin Solutions Inc.
Search Engine Optimisation provided by DragonByte SEO (Lite) - vBulletin Mods & Addons Copyright © 2025 DragonByte Technologies Ltd.
MSOfficeForums.com is not affiliated with Microsoft