• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User


  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

Rename multiple worksheets in a folder to the respective workbook names


New Member

I would appreciate the help on the below task.
I have multiple excel files in a folder and i want to set the name of worksheet 2 of each file as the name of corresponding excel workbook name.
Can someone help me on this please.
Hi Nagu,

I modified the code from here: www.thespreadsheetguru.com/the-code-vault/2014/4/23/loop-through-all-excel-files-in-a-given-folder

It worked when I tested it.

Sub LoopyOne()
Dim wb As Workbook
Dim myPath As String, myFile As String, myExtension As String
Dim FldrPicker As FileDialog
Application.ScreenUpdating = False
Application.EnableEvents = False
Application.Calculation = xlCalculationManual
Set FldrPicker = Application.FileDialog(msoFileDialogFolderPicker)
With FldrPicker
        .Title = "Select A Target Folder"
        .AllowMultiSelect = False
        If .Show <> -1 Then GoTo NextCode
        myPath = .SelectedItems(1) & "\"
End With
myPath = myPath
If myPath = "" Then GoTo ResetSettings
myExtension = "*.xls*"
myFile = Dir(myPath & myExtension)
Do While myFile <> ""
Set wb = Workbooks.Open(Filename:=myPath & myFile)
wb.Worksheets(2).Name = wb.Name
wb.Close savechanges:=True
myFile = Dir
MsgBox "All Done"
Application.EnableEvents = True
Application.Calculation = xlCalculationAutomatic
Application.ScreenUpdating = True
End Sub

Mods: Sorry for not wrapping the code, I cannot see how it is done. I looked through the "New users start here" and did a search, I assume it is to do with BB code button but it just turns red?
Last edited by a moderator:
Your I looked through the "New users start here"
You seems to skipped next link:
as well as
Screenshot 2021-09-04 at 18.40.12.png
In a workbook as requested, be careful when running make sure you want all *.xls* files in the directory modified to suit. There is no error catching at the moment.


  • Rename sheet 2.xlsm
    19.8 KB · Views: 6