FilenameAsCell

hautoguy2021

New Member
Joined
Jan 8, 2021
Messages
8
Office Version
  1. 365
Platform
  1. Windows
I get "compile Error" "Syntax Error" when i run the macro in the worksheet. Any help here?

VBA Code:
Sub FileNameAsCellContent()
Dim FileName As String
Dim Path As String
Application.DisplayAlerts = False
Path = "C:\test\"
FileName = Range("E3").Value & ".xlsx"
ActiveWorkbook.SaveAs Path&FileName,xlOpenXMLWorkbook
Application.DisplayAlerts = True
ActiveWorkbook.Close
End Sub
 

Excel Facts

Show numbers in thousands?
Use a custom number format of #,##0,K. Each comma after the final 0 will divide the displayed number by another thousand

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
56,974
Office Version
  1. 365
Platform
  1. Windows
Welcome to the Board!

What is the exact entry in cell E3?
 

Fluff

MrExcel MVP, Moderator
Joined
Jun 12, 2014
Messages
56,695
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

You need a space before and after the & sign like
VBA Code:
ActiveWorkbook.SaveAs Path & FileName,xlOpenXMLWorkbook
I would also advise using words like Path & FileName for variables as they are VBA keywords & can cause problems.
 

Joe4

MrExcel MVP, Junior Admin
Joined
Aug 1, 2002
Messages
56,974
Office Version
  1. 365
Platform
  1. Windows
cell E3 contains customer name
I was wanting to the see EXACT value you have in there, to make sure that you do not have any illegal values.
There are restrictions regarding which characters that can be used in file names. So I was hoping to see your actual value.

If Fluff's response does not get rid of all your errors, please post that value for us.
 

hautoguy2021

New Member
Joined
Jan 8, 2021
Messages
8
Office Version
  1. 365
Platform
  1. Windows

ADVERTISEMENT

I was wanting to the see EXACT value you have in there, to make sure that you do not have any illegal values.
There are restrictions regarding which characters that can be used in file names. So I was hoping to see your actual value.

If Fluff's response does not get rid of all your errors, please post that value for us.
 

Watch MrExcel Video

Forum statistics

Threads
1,129,840
Messages
5,638,666
Members
417,041
Latest member
Molo

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