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 `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
The debugger points to` " ActiveWorkbook.SaveCopyAs Filename:="G:\My Drive\Backup\Backups Of Important Workbook" & _
Test1Str & "-" & TestStr & "-" & ActiveWorkbook.Name "
Sign in to comment
Sort by: Most helpful