Save workbook with sheet name macro

doriannjeshi

Active Member
Joined
Apr 5, 2015
Messages
338
Office Version
  1. 365
Platform
  1. Windows
Hi,
I need to save a workbook that has only that sheet as a xlsx file , to a certain path, by copying the name of the worksheet + todays date
 

Excel Facts

Get help while writing formula
Click the italics "fx" icon to the left of the formula bar to open the Functions Arguments dialog. Help is displayed for each argument.
Maybe

VBA Code:
Sub SaveFile()

    Dim fname As String, path As String, fDate As String

    fDate = Format(Date, "dd_mm_yyyy") ' change format to suit
    path = "YourFilePath" ' your file path without a closing \

    Application.DisplayAlerts = False
   
    fname = Sheets(1).Name & " " & fDate
    ActiveWorkbook.SaveAs Filename:=path & "\" & fname & ".xlsx", FileFormat:=51


End Sub
 
Last edited:
Upvote 1
I am running into a problem when running the macro through a shortcut , it is saving it as sheet1 instead of the real sheet name
 
Upvote 0
Maybe

VBA Code:
Sub SaveFile()

    Dim fname As String, path As String, fDate As String

    fDate = Format(Date, "dd_mm_yyyy") ' change format to suit
    path = "YourFilePath" ' your file path without a closing \

    Application.DisplayAlerts = False
 
    fname = Sheets(1).Name & " " & fDate
    ActiveWorkbook.SaveAs Filename:=path & "\" & fname & ".xlsx", FileFormat:=51


End Sub
@doriannjeshi , If by "Real" name you mean CodeName then simply change
VBA Code:
Sheets(1).Name
to
VBA Code:
Sheets(1).CodeName
 
Upvote 1
Thank you Skybot for the explanation
the shortcut I used for the macro saved it with sheetcode instead of the name
but switching to a new shortcut is not doing it anymore
 
Upvote 0

Forum statistics

Threads
1,225,399
Messages
6,184,749
Members
453,254
Latest member
topeb

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