• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 456
  • Last Modified:

automatically save MS word 2010 file

Is there anyway that I can let MS word 2010 automatically save document as xxx_mmddss.doc every 10 minutes by itself? Since I had incident as overwritten a file. Now I want to be extra cautious to save the file every 10 minutes as different names by itself.
0
xiaoyunwu
Asked:
xiaoyunwu
  • 2
1 Solution
 
Delphineous SilverwingGood Ol' GeekCommented:
You can do this with a macro - http://www.gmayor.com/save_numbered_versions.htm is a good reference that with some manipulation will give you the filename format you seek.
0
 
EirmanCommented:
This software does incremental word file backups, which is what you are looking for.
http://www.downloadatlas.com/free-to-try-2c2b4aa4.html
0
 
xiaoyunwuAuthor Commented:
Hi Dephineous,
The link was great, I used the link and changed the macro sub name to FileSave(), so now whenever user click on "save", the file will be saved as another version. The problem I have now is: I'd like the macro to be called every 10 minutes automatically and save. So I added the following line at the end: Application.OnTime Now + TimeValue("00:10:00"), "FileSave", but it does not work. Any idea?

Sub FileSave()
'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) Mod 10) + 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"
Application.OnTime Now + TimeValue("00:10:00"), "FileSave"
End Sub

Open in new window

0
 
xiaoyunwuAuthor Commented:
I figured out.
Application.OnTime Now + TimeValue("00:10:00"), "FileSave" should be at the different place. Should be before "exist Sub"

Sub FileSave()
'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) Mod 10) + 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

Application.OnTime Now + TimeValue("00:10:00"), "FileSave"

Exit Sub
CancelledByUser: 'Error handler
MsgBox "Cancelled By User", , "Operation Cancelled"

End Sub
                                            

Open in new window

0

Featured Post

[Webinar] Cloud and Mobile-First Strategy

Maybe you’ve fully adopted the cloud since the beginning. Or maybe you started with on-prem resources but are pursuing a “cloud and mobile first” strategy. Getting to that end state has its challenges. Discover how to build out a 100% cloud and mobile IT strategy in this webinar.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now