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

Remove leading & trailing spaces
Save as CSV to remove all leading and trailing spaces. It is faster than using TRIM().
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,214,870
Messages
6,122,019
Members
449,060
Latest member
LinusJE

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