VBA SaveAs RunTime Error 1004

Anna_Od

New Member
Joined
Jun 26, 2020
Messages
3
Platform
  1. Windows
Hello,
I keep receiving RunTime Error 1004 at the saveAs line of my code. The code is below. I have tried multiple different solutions people have posted, but it doesn't help.

VBA Code:
Private Sub CommandButton1_Click()
Dim Path As String
Dim Name As String
Dim Loc As String

    Set wb = Workbooks.Add

ThisWorkbook.Activate
Application.Calculate
If Not Application.CalculationState = xlDone Then
DoEvents
    End If

    Path = ThisWorkbook.Sheets("Sheet1").Range("C27").Value
    Name = ThisWorkbook.Sheets("Sheet1").Range("C2").Value & "_" & Format(Date, "ddmmyyyy") & "_" & Format(Time, "hh:mm:ss")
    Loc = Path & "\" & Name & ".xlsm"

    ThisWorkbook.Sheets("Summary").Copy Before:=wb.Sheets(1)
wb.Activate
ActiveWorkbook.SaveAs FileName:=Path & "\" & Name & ".xlsm", _
        FileFormat:=xlOpenXMLWorkbookMacroEnabled, CreateBackup:=False
---> rest of code

The value of C27 is the file path inputted by user
The value of C2 is the type of summary needed also inputted by user
 

Excel Facts

Formula for Yesterday
Name Manager, New Name. Yesterday =TODAY()-1. OK. Then, use =YESTERDAY in any cell. Tomorrow could be =TODAY()+1.
Hi & welcome to MrExcel.
You cannot have colons as part of the filename, so you will have to change the format of the time portion of the filename.
 
Upvote 0
You're welcome & thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,224,765
Messages
6,180,845
Members
453,001
Latest member
coulombevin

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