Macro to save concatenate names

Tigrou25

New Member
Joined
Nov 22, 2018
Messages
14
Hi all,

I have created a macro to extract few tabs from a spreadsheet and save a new spreadsheet.

I would like to save the new file using the month in the tab "Control_Page" (in cell B12).

I have tried the code below
ActiveWorkbook.SaveAs Filename:= _
"1. " & sheets("Control_Page".Range("B12")&" Monthly P&L Review.xlsx"
which doesn't work.

The idea would be to have the following file name
1. Oct 18 Monthly P&L Review.xlsx
with Oct18 being cell B12 in the tab "Control_Page"

Thanks for your help
 
Here's the tab Control_Page and cell B12.

This is the right name

2m63nlt.png


I have added the value to the string but now I have a syntax error.

Here is the code
Code:
 ChDir "S:\Construction\National - Head Office\A Profit and Loss\A01 FY Budgets\08. FY19 P&L\1.Monthly P&L Review"ActiveWorkbook.SaveAs Filename:= _
"1. " & Sheets("Control_Page").Range("B12") .value & " Monthly P&L Review.xlsx" _
, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
 
Upvote 0

Excel Facts

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
Have a look at the syntax for "Control_Page" in your code .....then look at the sheet Tab syntax Control_page
There is a difference !
 
Last edited:
Upvote 0
No more luck with this one, still syntax error
Code:
        ChDir "S:\Construction\National - Head Office\A Profit and Loss\A01 FY Budgets\08. FY19 P&L\1.Monthly P&L Review"ActiveWorkbook.SaveAs Filename:= _"1. " & Sheets("Control_page").Range("B12") .value & " Monthly P&L Review.xlsx" _
, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
 
Upvote 0
Ok, you stated previously that you could save it this way if you used a standard name ??
But not when you use Rnge (B12)......So, there must be an issue with B12 !
Try setting as a variable like
Code:
Set mydate =  Sheets("Control_page").Range("B12") .value
then use

Code:
ChDir "S:\Construction\National - Head Office\A Profit and Loss\A01 FY Budgets\08. FY19 P&L\1.Monthly P&L Review"
ActiveWorkbook.SaveAs Filename:= _"1. " & mydate & " Monthly P&L Review.xlsx" _
, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
If you then test it line by line using F8, when you hover the mouse over mydate in the save line it should tell you if it is correct or not !

Otherwise upload the file to dropbox and we'll take a look at it.
 
Last edited:
Upvote 0
Like this ?

Code:
Set mydate =  Sheets("Control_page").Range("B12") .value        ChDir "S:\Construction\National - Head Office\A Profit and Loss\A01 FY Budgets\08. FY19 P&L\1.Monthly P&L Review"
ActiveWorkbook.SaveAs Filename:= _"1. " & mydate & " Monthly P&L Review.xlsx" _
, FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
 
Upvote 0
What happens if you just use this and see if it does as required

Code:
Sub MM1()
Set mydate = Sheets("Control_page").Range("B12")
ActiveWorkbook.SaveAs Filename:="1. " & mydate & " Monthly P&L Review.xls", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
End Sub
 
Last edited:
Upvote 0
This code is saving the file with the correct name including the month in documents.

I have added the location to save the file but it still saving in documents

Code:
ChDir "S:\Construction\National - Head Office\A Profit and Loss\A01 FY Budgets\08. FY19 P&L\1.Monthly P&L Review"Set mydate = Sheets("Control_page").Range("B12")
ActiveWorkbook.SaveAs Filename:="1. " & mydate & " Monthly P&L Review.xls", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
 
Last edited:
Upvote 0
Ok, so now what does this do ??
Code:
Dim fpath As String
fpath = "S:\Construction\National - Head Office\A Profit and Loss\A01 FY Budgets\08. FY19 P&L\1.Monthly P&L Review\"
Set mydate = Sheets("Control_page").Range("B12")
ActiveWorkbook.SaveAs Filename:=fpath & "1. " & mydate & " Monthly P&L Review.xls", FileFormat:=xlOpenXMLWorkbook, CreateBackup:=False
 
Upvote 0
I'm afraid without seeing the workbook, I can't really help any further.
If you are getting to the line you highlighted in yellow, then it isn't the SaveAs that's causing the problem.

Is "Control_Page" protected ???
 
Upvote 0

Forum statistics

Threads
1,215,777
Messages
6,126,832
Members
449,343
Latest member
DEWS2031

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