Save workbook with sheet name macro

doriannjeshi

Active Member
Joined
Apr 5, 2015
Messages
326
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

Shade all formula cells
To shade all formula cells: Home, Find & Select, Formulas to select all formulas. Then apply a light fill color.
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,224,272
Messages
6,177,632
Members
452,786
Latest member
k3calloway

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