Microsoft Office Tutorials and References
In Depth Information
Saving a Backup Copy of a Workbook
' * * * * *¶
Function GetExtension(FileName As String) As String¶
'Variable declaration¶
Dim i As Long¶
For i = Len(FileName) To 1 Step -1¶
If Mid$(FileName, i, 1) = "." Then¶
GetExtension = Mid$(FileName, i + 1)¶
Exit Function¶
End If¶
Next i¶
End Function¶
' * * * * *¶
Function FileExists(sFullName As String) As Boolean¶
FileExists = Len(Dir(PathName:=sFullName)) > 0¶
End Function¶
View the Appendix to learn how to store this procedure
in a ThisWorkbook module.
Option Explicit¶
' * * * * *¶
Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, _¶
Cancel As Boolean)¶
If SaveAsUI Then¶
'Only save backup if the workbook is being saved from Excel¶
SaveBackup Me¶
End If¶
End Sub¶
The first part of the code goes in a standard module in the workbook or
template of interest. The rest goes in the ThisWorkbook module of the same
Tip: Change the Path to the folder where the backups are to be stored and the History constant
to the number of older versions to keep in the path.
Search JabSto ::

Custom Search