Microsoft Office Tutorials and References
In Depth Information
Saving a Backup Copy of a Workbook
Saving a Backup Copy of a Workbook
Using this procedure, you can create a backup of copy of your workbook in a
different location (such as a server) each time you save it.
Example file:
Scenario: When working with data, it is important to have
procedures that allow the company or department to recover
as painlessly and quickly as possible from a disaster. One
common procedure is to do a backup of the information to a
remote location—a server located in a different geographical
spot—to diminish the chances of loss of data.
View the Appendix to learn how to store this procedure
in a Standard module.
Option Explicit¶
' * * * * *¶
Sub SaveBackup(Optional Book As Workbook)¶
'Call this macro from the BeforeSave event of the workbook¶
'Variable declaration¶
Dim Path As String¶
Dim FileNoExtension As String¶
Dim Extension As String¶
Dim TempFile As String¶
Dim i As Long¶
'Change the following variables¶
'Number of old versions to save¶
'If set to 0, no older version is kept¶
Const History As Long = 3¶
'Hard coded Path value¶
'Path = "\\Server\apps\"¶
'Path = "C:\"¶
'User inputs Path variable¶
Path = Range("B1").Value¶
On Error GoTo err_h¶
'If workbook isn't identified, assume the active workbook¶
If Book Is Nothing Then¶
Set Book = ActiveWorkbook¶
End If¶
'Does the folder exist?¶
If Len(Dir$(PathName:=Path, Attributes:=vbDirectory)) = 0 Then¶
MkDir Path¶
End If¶
Search JabSto ::

Custom Search