Consulting

Results 1 to 3 of 3

Thread: Any way to rename Sheet1 to the name of the Workbook when you save?

  1. #1

    Any way to rename Sheet1 to the name of the Workbook when you save?

    Hello

    Does anyone know any VBA I can use to rename Sheet1 to the name of the Workbook when I save?

    For example, I create a new workbook. I click File -> Save As -> And save it as "Hello.xls".

    I would like Sheet1 in Hello.xls to automatically be renamed to Hello.

    Is this possible?

    Thank you!

  2. #2
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,453
    Location
    Try this

    [vba]

    Private Sub Workbook_BeforeSave(ByVal SaveAsUI As Boolean, Cancel As Boolean)
    Dim sFile
    If SaveAsUI Then
    Application.EnableEvents = False
    Cancel = True
    sFile = Application.GetSaveAsFilename("","Excel Files (*.xls), *.xls")
    If sFile <> False Then
    sFile = Right(sFile, Len(sFile) - InStrRev(sFile, "\"))
    ThisWorkbook.Worksheets(1).Name = Replace(sFile, ".xls", "")
    ThisWorkbook.SaveAs sFile
    End If
    End If
    Application.EnableEvents = True
    End Sub
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

  3. #3
    Works perfectly

    Thank you xld!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •