RUN TIME ERROR 1004

EinarOSies

Board Regular
Joined
Feb 15, 2021
Messages
61
Office Version
  1. 2019
Platform
  1. 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
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
The debugger points to " ActiveWorkbook.SaveCopyAs Filename:="G:\My Drive\Backup\Backups Of Important Workbook" &
Test1Str & "-" & TestStr & "-" & ActiveWorkbook.Name
 
Last edited by a moderator:

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop
As I see it the only reason for 'error 1004' is a typo in the SaveAs path. Are you sure of "G:\My Drive\Backup\" or maybe the destination should be:
Filename:="G:\My Drive\Backup\Backups Of Important Workbook" & "\" & Test1Str & "-" & TestStr & "-" & ActiveWorkbook.Name with an extra path separator.
 
Last edited:
Upvote 0

Forum statistics

Threads
1,214,402
Messages
6,119,304
Members
448,886
Latest member
GBCTeacher

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top