Revision Number

  • Thread starter Thread starter Sean Horvath
  • Start date Start date
S

Sean Horvath

Is there a way to automatically add the file revision number to the file
name of a Word Doc?

I am looking at updating documentation and automatically putting this
information in.

Thanks,
Sean.
 
Do you actually want to save different numbered versions of the file? In
which case the following macro will do that and retain the earlier versions
which might be the safest way to handle this. You need to set the preferred
start filename and path where indicated. The macro stores the incremented
numbers to a file c:\settings.txt. If the document is unnamed the macro
provides the opportunity to name it and will save that first version both
with the filename you choose and Filename Version 001.doc.. It doesn't
matter which version you are working with at the time, the macro always
saves with the next available number. I suggest adding the macro to a
toolbar button rather than using it to intercept the file save function.
http://www.gmayor.com/installing_macro.htm . You can display the filename
with version number by using a filename field in the document.

Sub SaveNumberedVersion()
'Graham Mayor 15 Jan 2006
'Based on code by Doug Robbins
Dim strPath As String
Dim strFile As String
Dim strDocname As String
Dim intPos As Integer

strFile = ActiveDocument.Name
intPos = InStrRev(strFile, ".")
If intPos = 0 Then 'document not saved
ActiveDocument.Save 'so save it
End If

strPath = ActiveDocument.Path 'Get path
strFile = ActiveDocument.Name 'Get document name

intPos = InStrRev(strFile, "V") 'Try again
If intPos = 0 Then
intPos = InStrRev(strFile, ".")
strFile = Left(strFile, intPos - 1) 'Strip filename extension
Else
strFile = Left(strFile, intPos - 2)
End If
Order = System.PrivateProfileString("C:\Settings.Txt", _
"MacroSettings", strFile & "Order") 'Lookup the current number
If Order = "" Then 'Increment that number by 1
Order = 1
Else
Order = Order + 1
End If

System.PrivateProfileString("C:\Settings.txt", "MacroSettings", _
strFile & "Order") = Order 'Update the number record
'Define the new version filename
strDocname = strPath & "\" & strFile & " Version " & Format(Order, "00#") &
".doc"
ActiveDocument.SaveAs strDocname 'and save a copy of the file with that name
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
Back
Top