FriedEgg
FriedEgg

Reputation: 23

Saving sheet to a location using the title of the sheet to name the file

I have written for a button -

Private Sub CommandButton1_Click()

    Dim path As String
    Dim filename1\ As String

    path = C:\Users\Barb\Desktop\demo\"
    filename1 = Range("C4").Text
    Application.DisplayAlerts = False
    ActiveWorkbook.SaveAs Filename1=path & filename1 & ".xlsx", 
    FileFormatxlOpenXMLWorkbook
    Application.DisplayAlerts = True
    ActiveWorkbook.Close

End Sub

How can I tell it when saving the sheet to use the title of the sheet tab

Upvotes: 0

Views: 20

Answers (2)

Guy Louzon
Guy Louzon

Reputation: 1213

something like, for example:

filename1 = sheets(1).name

Or

filename1 = activesheet. name

Upvotes: 1

cybernetic.nomad
cybernetic.nomad

Reputation: 6418

Assuming you are talking about the ActiveSheet, change:

filename1 = Range("C4").Text

to:

filename1 = ActiveSheet.Name

Upvotes: 1

Related Questions