VBA Files Save As - Syntax

GDunn

Board Regular
Joined
Mar 24, 2009
Messages
51
Hi,

I am having some trouble with a Save As code.
Trying to provide a specific location, with the actual file name being taken from a cell in the file.

ActiveWorkbook.SaveAs Filename:="C:\xxxxx\xxxxxxxx\xxxxxxxxxxx\xxxx\" & Range("D16").Value & ".xlsm"

Can you please help with my syntax, as when I run this it errors on the file location.

Thanks,
 

Excel Facts

Workdays for a market open Mon, Wed, Friday?
Yes! Use "0101011" for the weekend argument in NETWORKDAYS.INTL or WORKDAY.INTL. The 7 digits start on Monday. 1 means it is a weekend.
Hi

I expect it errors because you aren't supplying the FileFormat argument:

Code:
ActiveWorkbook.SaveAs Filename:="C:\xxxxx\xxxxxxxx\xxxxxxxxxxx\xxxx\" & Range("D16").Value & ".xlsm", FileFormat:=52 'xlOpenXMLWorkbookMacroEnabled

Also, check that you don't have any invalid characters in the referenced range.
 
Upvote 0
I just tried to record some code to check your syntax and it appears to be correct. Code I got was:
Code:
ActiveWorkbook.SaveAs Filename:="E:\Maphisto.xls"
I then placed the file name into a cell, changed code to:
Code:
ActiveWorkbook.SaveAs Filename:="E:\" & Range("A1")
Then got distracted and pulled my removable drive out and the above didn't work, until I put the drive back in. To me your code looks virtually the same so I guess the error is in the actual path you've given in the code itself.

Or now having read Richard's reply, his reasons are probably more likely than mine!!
 
Upvote 0
Thanks for your help.

FileFormat wasn't needed. Had an underscore in file location....

Must need sleep.
 
Upvote 0

Forum statistics

Threads
1,224,599
Messages
6,179,831
Members
452,946
Latest member
JoseDavid

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