Home Excel Powerpoint Word Outlook Error Codes

VBA Useful Codes

Welcome to the World of VBA
Home > VBAUsefulCodes

Excel Macro to rename a worksheet

Renaming is simply done by setting new name of the worksheet to the .Name property of a worksheet as shown in below code

Sub renameWorksheet()
    Dim wb As Workbook
    Dim sh As Worksheet

    Dim newSheetName As String
    newSheetName = "MYNEWSHEETNAME"

    Dim fPath As String

    fPath = "C:\myfile.xlsx"
    Set wb = workbooks.Open(Filename:=fPath)
    ' Rename the sheet name of the 1st sheet
    Set sh = wb.Worksheets(1)
    sh.Name = newSheetName

End Sub


Enter your e-mail below and get notified on the latest blog posts.


VBA Outlook KPI Excel Alt+F11 Dashboards Macros Recording Graphs Automation Developer WaterFall Powerpoint Charts Pivot Tables Forecast Charts

Follow Us