File Format

billandrew

Well-known Member
Joined
Mar 9, 2014
Messages
743
Good Evening Could someone assist. I am attempting to save a current sheet (Active sheet) into a new workbook and include in the Name the reference to Range B2 which is Start & C2, which is the user input date. Also would like to include B3, which is the End & C3 which is the user input end date. A bit perplexed here....Dim FilePath$, Filename$ActiveSheet.CopyFilePath = CreateObject("WScript.Shell").SpecialFolders("Desktop") & Application.PathSeparatorFilename = ActiveSheet.NameActiveWorkbook.SaveAs Filename:=FilePath & Filename & " " & Range("B2") & " " & Range("C2") & ".xlsx", FileFormat:=51
 
Last edited:

Excel Facts

Waterfall charts in Excel?
Office 365 customers have access to Waterfall charts since late 2016. They were added to Excel 2019.
Code:
ActiveSheet.SaveAs Filename:=FilePath & Filename & " " & Range("B2") & " " & Range("C2") & ".xlsx", FileFormat:=51
 
Upvote 0
Check for legal filename. That means that the drive and folder must exist as well. Do a run and View the Immediate Window after to see the result.

Code:
Debug.Print FilePath & Filename & " " & Range("B2") & " " & Range("C2") & ".xlsx"

For others, record a macro to get the fileformat or see a site like: https://docs.microsoft.com/en-us/office/vba/api/excel.xlfileformat
 
Last edited:
Upvote 0
I believe I figured out the issue. Range is a Date which is formatted as mm/dd/yyyy. The workbook will not save with the forward slash. Need to work around this issue.Thank you Maybe someone has an alternative
 
Upvote 0
That is a typical issue. Use Format() to format the range's date with a valid filename like "mm-dd-yyyy".
 
Upvote 0

Forum statistics

Threads
1,224,743
Messages
6,180,686
Members
452,994
Latest member
Janick

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