VBA Save as giving error

ExcelNoob222

Board Regular
Joined
Jun 17, 2020
Messages
76
Office Version
  1. 365
Platform
  1. Windows
Hi all,

I have the below VBA code to save a file but I get a "Run-Time error '1004': Method 'SaveAs' of object '_workbook' failed.

It then highlights this row: ActiveWorkbook.SaveAs filename:=Path & filename & " Template.xlsx", FileFormat:=51

VBA Code:
 ET.Activate
    Dim Path As String
    Dim filename As String
    Path = "C:\New"
    filename = Range("C8")
    ActiveWorkbook.SaveAs filename:=Path & filename & " Template.xlsx", FileFormat:=51
    ActiveWorkbook.Close False


I cant seem to get this fixed. Any ideas?
 

Excel Facts

Can a formula spear through sheets?
Use =SUM(January:December!E7) to sum E7 on all of the sheets from January through December

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
77,894
Office Version
  1. 365
Platform
  1. Windows
What is in C8?
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
65,567
Office Version
  1. 365
Platform
  1. Windows
What is in cell C8?

In these cases, it is often helpful to return what you are building to a MsgBox, so you can see exactly what it is you are trying to save, i.e.
Rich (BB code):
 ET.Activate
    Dim Path As String
    Dim filename As String
    Path = "C:\New"
    filename = Range("C8")
    MsgBox Path & filename & " Template.xlsx"
    ActiveWorkbook.SaveAs filename:=Path & filename & " Template.xlsx", FileFormat:=51
    ActiveWorkbook.Close False
Often times when you see it, the issue is obvious (missing directory slashes, using invalid characters in file name, like date slashes, etc).
 

ExcelNoob222

Board Regular
Joined
Jun 17, 2020
Messages
76
Office Version
  1. 365
Platform
  1. Windows
What is in cell C8?

In these cases, it is often helpful to return what you are building to a MsgBox, so you can see exactly what it is you are trying to save, i.e.
Rich (BB code):
 ET.Activate
    Dim Path As String
    Dim filename As String
    Path = "C:\New"
    filename = Range("C8")
    MsgBox Path & filename & " Template.xlsx"
    ActiveWorkbook.SaveAs filename:=Path & filename & " Template.xlsx", FileFormat:=51
    ActiveWorkbook.Close False
Often times when you see it, the issue is obvious (missing directory slashes, using invalid characters in file name, like date slashes, etc).

Ahhh that is a great idea. Had an "illegal" character in the cell. Thank you!
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
65,567
Office Version
  1. 365
Platform
  1. Windows
You are welcome.
Glad we were able to help.
 

Forum statistics

Threads
1,176,598
Messages
5,903,961
Members
435,061
Latest member
CGA

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