Home |
Search |
Today's Posts |
#1
|
|||
|
|||
Macro help Word 2010
Hi there,
I've been looking for a macro for word 2010 which would help me with automatically editing the filenames of word documents as a crude form of version control. After some searching I found the follow macro which was written by Graham Mayor: Sub SaveNumberedVersion() 'Graham Mayor 15 Jan 2006 'Completely Revised 18 January 2011 'to store count in a document variable 'and improve document type handling Dim strVer As String Dim strDate As String Dim strPath As String Dim strFile As String Dim oVars As Variables Dim strFileType As WdDocumentType Dim strVersionName As String Dim intPos As Long Dim sExt As String Set oVars = ActiveDocument.Variables strDate = Format((Date), "dd MMM yyyy") With ActiveDocument On Error GoTo CancelledByUser If Len(.Path) = 0 Then 'No path means document not saved .Save 'So save it End If strPath = .Path 'Get path strFile = .Name 'Get document name End With intPos = InStr(strFile, " - ") 'Mark the version number sExt = Right(strFile, Len(strFile) - InStrRev(strFile, ".do")) If intPos = 0 Then 'No version number intPos = InStrRev(strFile, ".do") 'Mark the extension instead End If strFile = Left(strFile, intPos - 1) 'Strip the extension or version number Select Case LCase(sExt) 'Determine file type by extension Case Is = "doc" strFileType = 0 Case Is = "docx" strFileType = 12 Case Is = "docm" strFileType = 13 Case Is = "dot" strFileType = 1 Case Is = "dotx" strFileType = 14 Case Is = "dotm" strFileType = 15 End Select Start: 'Get Registry Data On Error Resume Next 'No entry in registry will flag an error strVer = oVars("varVersion").Value If strVer = "" Then 'Variable does not exist oVars("VarVersion").Value = "0" 'So create it GoTo Start: End If On Error GoTo 0 strVer = Val(strVer) + 1 'Increment number oVars("varVersion").Value = strVer 'Define the new version filename strVersionName = strPath & "\" & strFile & " - " & strDate & _ " - Version " & Format(Val(strVer), "00#") _ & Chr(46) & sExt 'and save a copy of the file with that name ActiveDocument.SaveAs strVersionName, strFileType Exit Sub CancelledByUser: 'Error handler MsgBox "Cancelled By User", , "Operation Cancelled" End Sub You can find the original posting on his website at: http://www.gmayor.com/save_numbered_versions.htm I added this to word and have been using it for a while but it doesn't quite accomplish what I would like. I was wondering if anyone could advise how to edit this macro so that the version number doesn't reset when a new date is added to the file name. For example: If I started a new word document on 10/10/2014 and saved it 7 times I would have a filename ending in: version 007. If I opened the same file on the following day (11/10/2014) and saved it the date in the filename would change and the document's version number would now reset to 001. So in a nutshell can this reseting of the version number on every new day be removed? Any help would be greatly appreciated, I am a complete beginner when it comes to macros and vba. Cheers Last edited by Gryphonn : October 15th 14 at 02:40 PM |
#2
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Macro help Word 2010
If you need assistance with installing the macro(s), go to
http://www.gmayor.com/installing_macro.htm. -- Stefan Blom Microsoft Word MVP "Gryphonn" wrote in message ... http://www.gmayor.com/save_numbered_versions.htm -- Gryphonn |
#3
|
|||
|
|||
Quote:
|
#4
Posted to microsoft.public.word.docmanagement
|
|||
|
|||
Macro help Word 2010
I don't see that question in this thread, with the subject "Macro help Word
2010." You will have to clarify what changes you want. Of course, the first step is to post your code. -- Stefan Blom Microsoft Word MVP "Gryphonn" wrote in message ... 'Stefan Blom[_3_ Wrote: ;495587']If you need assistance with installing the macro(s), go to http://www.gmayor.com/installing_macro.htm. -- Stefan Blom Microsoft Word MVP "Gryphonn" wrote in message ...- http://www.gmayor.com/save_numbered_versions.htm -- Gryphonn - The issue is not with installing the Macro, as I said in my original post I'm having trouble working out how to edit the Macro. -- Gryphonn |
#5
|
|||
|
|||
Quote:
I've been looking for a macro for word 2010 which would help me with automatically editing the filenames of word documents as a crude form of version control. After some searching I found the follow macro which was written by Graham Mayor: Sub SaveNumberedVersion() 'Graham Mayor 15 Jan 2006 'Completely Revised 18 January 2011 'to store count in a document variable 'and improve document type handling Dim strVer As String Dim strDate As String Dim strPath As String Dim strFile As String Dim oVars As Variables Dim strFileType As WdDocumentType Dim strVersionName As String Dim intPos As Long Dim sExt As String Set oVars = ActiveDocument.Variables strDate = Format((Date), "dd MMM yyyy") With ActiveDocument On Error GoTo CancelledByUser If Len(.Path) = 0 Then 'No path means document not saved .Save 'So save it End If strPath = .Path 'Get path strFile = .Name 'Get document name End With intPos = InStr(strFile, " - ") 'Mark the version number sExt = Right(strFile, Len(strFile) - InStrRev(strFile, ".do")) If intPos = 0 Then 'No version number intPos = InStrRev(strFile, ".do") 'Mark the extension instead End If strFile = Left(strFile, intPos - 1) 'Strip the extension or version number Select Case LCase(sExt) 'Determine file type by extension Case Is = "doc" strFileType = 0 Case Is = "docx" strFileType = 12 Case Is = "docm" strFileType = 13 Case Is = "dot" strFileType = 1 Case Is = "dotx" strFileType = 14 Case Is = "dotm" strFileType = 15 End Select Start: 'Get Registry Data On Error Resume Next 'No entry in registry will flag an error strVer = oVars("varVersion").Value If strVer = "" Then 'Variable does not exist oVars("VarVersion").Value = "0" 'So create it GoTo Start: End If On Error GoTo 0 strVer = Val(strVer) + 1 'Increment number oVars("varVersion").Value = strVer 'Define the new version filename strVersionName = strPath & "\" & strFile & " - " & strDate & _ " - Version " & Format(Val(strVer), "00#") _ & Chr(46) & sExt 'and save a copy of the file with that name ActiveDocument.SaveAs strVersionName, strFileType Exit Sub CancelledByUser: 'Error handler MsgBox "Cancelled By User", , "Operation Cancelled" End Sub You can find the original posting on his website at: http://www.gmayor.com/save_numbered_versions.htm I added this to word and have been using it for a while but it doesn't quite accomplish what I would like. I was wondering if anyone could advise how to edit this macro so that the version number doesn't reset when a new date is added to the file name. For example: If I started a new word document on 10/10/2014 and saved it 7 times I would have a filename ending in: version 007. If I opened the same file on the following day (11/10/2014) and saved it the date in the filename would change and the document's version number would now reset to 001. So in a nutshell can this reseting of the version number on every new day be removed? Any help would be greatly appreciated, I am a complete beginner when it comes to macros and vba. Cheers -------------------------------------------------------------------------------- Last edited by Gryphonn : October 15th 14 at 01:40 PM. This was the original post. |
Reply |
Thread Tools | |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Macro to print current page only in Word 2010 isn't working | Microsoft Word Help | |||
Turn off date and time - macro needed for 2010? | Microsoft Word Help | |||
Issue with Record Macro feature Word 2010 | Microsoft Word Help | |||
Word 2010 Macro | Microsoft Word Help | |||
Macro's not working in word 2010 | Microsoft Word Help |