Excel Macro - referencing a cell containing a formula as a file name

mattyblueice

Board Regular
Joined
Jul 24, 2014
Messages
85
Office Version
  1. 365
Platform
  1. MacOS
I have been trying to modify my macro to have it reference a cell (contains a formula) as the file name, but I just can't get it to work. The portion of the macro is:
ActiveWorkbook.SaveAs FileName: _
"C:\Users\Matt\Documents\Project Data\&"A20" _
, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False

The cell in A20 is this formula: CONCATENATE("Project Status ",TEXT(NOW(),"mm/dd/yyyy hh:mm am/pm")

The materials I have seem to indicate that this should work, but is it because the cell being referenced is a formula and not text? If so, anyway around that?

Thanks for your help!!!

Matt
 

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
You cannot save files where the name contains signs such as: / :

Replace your formula for this:

=CONCATENATE ("Project Status ",TEXT(NOW(),"mm-dd-yyyy hh-mm am/pm"))

And your macro for this:

VBA Code:
Sub test()
  Dim sPath As String
  Application.DisplayAlerts = False
  sPath = "C:\Users\Matt\Documents\Project Data\"
  ActiveWorkbook.SaveAs Filename:=sPath & Range("A20"), FileFormat:=xlOpenXMLWorkbook
End Sub
 
Upvote 0
Filenames cannot contain the forward slash character "/". Try using:
TEXT(NOW(),"mm.dd.yyyy hh:mm am/pm")
 
Upvote 0
And you cannot reference the range A20 in your formula in VBA like "A20". That will literally put in the text value "A20".
You must use Range("A20")
 
Upvote 0
Yes Of Course!!!! Ugh - why didn't I see that before. HAHA - thanks so much
 
Upvote 0
I'm glad to help you. Thanks for the feedback.
 
Upvote 0

Forum statistics

Threads
1,215,248
Messages
6,123,873
Members
449,130
Latest member
lolasmith

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