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

Difference between two dates
Secret function! Use =DATEDIF(A2,B2,"Y")&" years"&=DATEDIF(A2,B2,"YM")&" months"&=DATEDIF(A2,B2,"MD")&" days"
Welcome to the Board!

What is the exact entry in cell E3?
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0
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.
 
Upvote 0

Forum statistics

Threads
1,212,938
Messages
6,110,775
Members
448,298
Latest member
carmadgar

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