PDA

View Full Version : How to save as CSV file with the filename being dynamic and worksheet name static?



chadknudson
09-14-2015, 02:48 PM
I'm trying to prompt a user to save a .xls file as .csv and allowing them to change the file name. However, when they do this it's naming the worksheet the same as the file name they select when I want the worksheet name to stay static and listed as "SHEET". How can I retain the worksheet name of SHEET but allow the user to change the file name for a CSV file? Here is the code I'm using...


'Browse to save Apartment Types as .csv in location specified
Sheets("Apartment_Types").Select
Sheets("Apartment_Types").Name = "SHEET"
fileSaveName = Application.GetSaveAsFilename( _
InitialFileName:="C:\temp\Apartment_Types" + ".csv", _
fileFilter:="CSV Files (*.csv), *.csv")
If fileSaveName = False Then
Exit Sub
End If
ActiveWorkbook.SaveAs Filename:= _
fileSaveName, FileFormat:=xlCSVMSDOS, _
CreateBackup:=False