BACKUP FILE

Einar Osei Sies 41 Reputation points
2021-03-12T21:23:12.557+00:00

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

End Sub

The debugger points to` " ActiveWorkbook.SaveCopyAs Filename:="G:\My Drive\Backup\Backups Of Important Workbook" & _
Test1Str & "-" & TestStr & "-" & ActiveWorkbook.Name "

0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Tom van Stiphout 1,696 Reputation points MVP
    2021-03-13T20:46:15.363+00:00

    Ican'treadcodethatisalltogetherratherthanproperlyformatted.

    0 comments No comments