RUN TIME ERROR 1004

EinarOSies

Board Regular
Joined
Feb 15, 2021
Messages
51
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

Return population for a City
If you have a list of cities in A2:A100, use Data, Geography. Then =A2.Population and copy down.

rollis13

Active Member
Joined
Jul 30, 2012
Messages
468
Office Version
  1. 2016
Platform
  1. Windows
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:

Forum statistics

Threads
1,140,917
Messages
5,703,166
Members
421,279
Latest member
emzy

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
Top