#1   Report Post  
Gryphonn Gryphonn is offline
Junior Member
 
Posts: 0
Default 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   Report Post  
Posted to microsoft.public.word.docmanagement
Stefan Blom[_3_] Stefan Blom[_3_] is offline
external usenet poster
 
Posts: 6,897
Default 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   Report Post  
Gryphonn Gryphonn is offline
Junior Member
 
Posts: 0
Default

Quote:
Originally Posted by Stefan Blom[_3_] View Post
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.
  #4   Report Post  
Posted to microsoft.public.word.docmanagement
Stefan Blom[_3_] Stefan Blom[_3_] is offline
external usenet poster
 
Posts: 6,897
Default 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   Report Post  
Gryphonn Gryphonn is offline
Junior Member
 
Posts: 0
Default

Quote:
Originally Posted by Stefan Blom[_3_] View Post
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
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 01:40 PM.

This was the original post.
Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Macro to print current page only in Word 2010 isn't working PRR Microsoft Word Help 4 July 23rd 17 03:59 PM
Turn off date and time - macro needed for 2010? kaye123 Microsoft Word Help 4 June 9th 14 02:06 AM
Issue with Record Macro feature Word 2010 mpdsal Microsoft Word Help 1 October 23rd 12 12:18 AM
Word 2010 Macro John[_17_] Microsoft Word Help 2 May 3rd 12 10:13 PM
Macro's not working in word 2010 louisechapman Microsoft Word Help 0 October 25th 10 11:19 AM


All times are GMT +1. The time now is 04:20 AM.

Copyright ©2000 - 2023, Jelsoft Enterprises Ltd.
Copyright 2004-2023 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"