EinarOSies
Board Regular
- Joined
- Feb 15, 2021
- Messages
- 61
- Office Version
- 2019
- Platform
- Windows
Please I got this code and I wanted it to backup my workbook to a different location. When running the macro it gives me a "Run-time error '1004':
Method 'SaveCopyAs' of object'Workbook' failed". I tried that on a different workbook and it worked but not on my initial one. My initial workbook has a password added to it. This is the code
The debugger points to " ActiveWorkbook.SaveCopyAs Filename:="G:\My Drive\Backup\Backups Of Important Workbook" &
Test1Str & "-" & TestStr & "-" & ActiveWorkbook.Name
Method 'SaveCopyAs' of object'Workbook' failed". I tried that on a different workbook and it worked but not on my initial one. My initial workbook has a password added to it. This is the code
VBA Code:
Sub AutoBackup()
If ActiveWorkbook.Path = "G:\My Drive\Backup\Backups Of Important Workbook" Then
Exit Sub
Else
Dim MyDate MyDate = Date ' MyDate contains the current system date.
Dim MyTime MyTime = Time ' Return current system time.
Dim TestStr As String TestStr = Format(MyTime, "hh.mm.ss")
Dim Test1Str As String Test1Str = Format(MyDate, "DD-MM-YYYY")
Application.DisplayAlerts = False
ActiveWorkbook.SaveCopyAs Filename:="G:\My Drive\Backup\Backups Of Important Workbook" & _ Test1Str & "-" & TestStr & "-" & ActiveWorkbook.Name
ActiveWorkbook.Save Application.DisplayAlerts = True
End If
End Sub
Test1Str & "-" & TestStr & "-" & ActiveWorkbook.Name
Last edited by a moderator: