PDA

View Full Version : Version-checking template and ribbon



Kuildeous
08-19-2015, 05:59 AM
Hi there. I have a template that I distribute to the team for creating specific Word documents. While I could programatically place the macros in the ribbon, it was just easier for our team for me to export the ribbon and have each team member import the ribbon into their Word profile, especially since they don't customize the ribbons on their own. For security reasons, I've been asked to place the template in a secured folder with instructions for each team member to copy the template over to their Templates folder on their machines.

I'm trying to implement a version checker to ensure that the team members are using the most recent version of the template. I'm trying not to make many changes to the template, but since there is a copyright in the footer, I have to update it at least once a year (though setting that in VBA based on the current year might be an option later). To do this, I am adding this code to AutoOpen:


Public Sub AutoOpen()
Const strFile = "O:\library\version_check.txt"
Const strVersion = "20150820_Template"
Const strRibbon = "20150820_Ribbon"
Dim strTextLine As String
Dim strText As String


Open strFile For Input As #1
Do Until EOF(1)
Line Input #1, strTextLine
strText = strText & strTextLine
Loop
Close #1


If InStr(1, strText, strRibbon, 0) > 0 Then
If InStr(1, strText, strVersion, 0) > 0 Then
' Do nothing, as the dates match.
Else
' Ribbon matches, but verion is out of date.
MsgBox "Warning: This template is out of date. Follow the SOP instructions for installing " & _
"the most recent template. You do not need to update the ribbon.", vbOKOnly, _
"Template out of date"
End If
Else
' Ribbon does not match, which means the version does not match either.
MsgBox "Warning: This template is out of date. Follow the SOP instructions for installing " & _
"the most recent template." & vbCr & vbCr & "There is also a new ribbon. " & _
"Follow the SOP instructions for copying over the most recent ribbon.", vbOKOnly, _
"Template out of date"
End If


End Sub


As you can probably guess, the version_check.txt file contains the two constants that should match what is hard-coded in the template. When I make an update, I change the date of the template and possibly the ribbon if I made a change there.

The biggest issue I see is that if a user has the most recent template installed but has not updated the ribbon, the program doesn't know. Is there a way to date-stamp the ribbon in a way that the code can check for the date and notify the user that the ribbon doesn't contain all of the template's commands?

I apologize for my rudimentary knowledge of VBA and the ugly method of replacing the ribbon. I may research loading the buttons into the ribbon via VBA later this year.

gmayor
08-19-2015, 08:59 PM
As this is a template, why not simply edit the template's ribbon? See http://gregmaxey.mvps.org/word_tip_pages/customize_ribbon_main.html . You don't need to add the buttons via VBA. You can edit the XML directly.

Kuildeous
08-20-2015, 06:37 AM
That helps a lot. Thanks.

I removed the reference to updating the ribbon in my AutoOpen. It does check a .TXT file to verify that the template is the most recent.

As for if I have a change to the ribbon, I have also added in AutoOpen code to check the Word.officeUI file for the unique ID I assigned to the new tab. The ID contains the date, and if this date does not match what I have in the template, it extracts the XML file, removes the code between that <tag> and its </tag>, and inserts the updated codes.

Indeed, it was not rocket science, and I'm glad I was able to sit down with this for a while and hash it out.