Save as xlsx to different location with current file name and append date

hinesgg

New Member
Joined
Jul 11, 2012
Messages
30
I have templates stored in a single location and I want the output stored in a different location with the same file name and date appended.

The code below works, but in it I specify the file name (in this example: Forecast HM SUPPLIERNAME). I would prefer for the file name to use the source file name and then just append the date.

Code:
ActiveWorkbook.SaveAs Filename:="\\aurnt503\Xcc$\11 Planning\New Reports\Forecast HM SUPPLIERNAME" & Format(Now, " mm-dd-yyyy") & ".xlsx", FileFormat:=51
Is this possible?
 

Excel Facts

Add Bullets to Range
Select range. Press Ctrl+1. On Number tab, choose Custom. Type Alt+7 then space then @ sign (using 7 on numeric keypad)
Maybe:
Code:
Dim fNam as string
fNam = Left(ActiveWorkbook.Name, InStr(1, ActiveWorkbook.Name, ".xls") - 1)
ActiveWorkbook.SaveAs Filename:="\\aurnt503\Xcc$\11 Planning\New Reports\" & fNam & Format(Now, " mm-dd-yyyy") & ".xlsx", FileFormat:=51
 
Last edited:
Upvote 0
The original file is an xlsm, not an xls, if that makes a difference. Sorry, I don't know much at all about VBA code.
 
Upvote 0
I got this to work properly by modifying the code to recognize the original file's xlsm format. Thanks for your help.


Code:
Dim fNam as stringfNam = Left(ActiveWorkbook.Name, InStr(1, ActiveWorkbook.Name, ".xlsm") - 1)ActiveWorkbook.SaveAs Filename:="\\aurnt503\Xcc$\11 Planning\New Reports\" & fNam & Format(Now, " mm-dd-yyyy") & ".xlsx", FileFormat:=51[\Code]</pre>
 
Upvote 0
I got this to work properly by modifying the code to recognize the original file's xlsm format. Thanks for your help.


Code:
Dim fNam as stringfNam = Left(ActiveWorkbook.Name, InStr(1, ActiveWorkbook.Name, ".xlsm") - 1)ActiveWorkbook.SaveAs Filename:="\\aurnt503\Xcc$\11 Planning\New Reports\" & fNam & Format(Now, " mm-dd-yyyy") & ".xlsx", FileFormat:=51[\Code][/QUOTE]
Shouldn't make any difference whether you use .xls or .xlsm in the InStr function. That simply locates the .xls in the string. I prefer .xls since that covers .xlsx and .xlsm and .xlsb type files.
 
Upvote 0

Forum statistics

Threads
1,223,236
Messages
6,170,906
Members
452,366
Latest member
TePunaBloke

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