Changing same tab name across workbooks

GARTHMAN

New Member
Joined
Apr 3, 2013
Messages
14
Greetings! Here is my dilemma... I have 364 workbooks that contain data specific to each day. Each workbook has 6 identical tab names. The only differentiation is the daily date in the name of the workbooks (i.e. "06-02-2022 TVM CC JOURNAL ENTRY DETAIL"). We are changing banks and the tab labeled "WELLS FARGO COMPARED to INTERNAL" needs to be changed to "CHASE BANK COMPARED TO INTERNAL". I can find info on changing tabs within a single workbook, but not on how to change the tab name across multiple workbooks using VBA or otherwise. Does anyone have a code that will do what I am seeking to do? Thanks in advance.
 

Excel Facts

Why are there 1,048,576 rows in Excel?
The Excel team increased the size of the grid in 2007. There are 2^20 rows and 2^14 columns for a total of 17 billion cells.
Change the file path (in red) to the path of the folder which contains the workbooks. The macro assumes the 364 workbooks are the only workbooks in that folder and the extension is "xlsx".
Rich (BB code):
Sub ReNameSheet()
    Application.ScreenUpdating = False
    Dim wkbDest As Workbook
    Const strPath As String = "C:\Test\"
    ChDir strPath
    strExtension = Dir(strPath & "*.xlsx")
    Do While strExtension <> ""
        Set wkbDest = Workbooks.Open(strPath & strExtension)
        Sheets("WELLS FARGO COMPARED to INTERNAL").Name = "CHASE BANK COMPARED TO INTERNAL"
        Application.DisplayAlerts = False
        ActiveWorkbook.Close True
        Application.DisplayAlerts = True
        strExtension = Dir
    Loop
    Application.ScreenUpdating = True
End Sub
 
Upvote 0
Solution
Change the file path (in red) to the path of the folder which contains the workbooks. The macro assumes the 364 workbooks are the only workbooks in that folder and the extension is "xlsx" for all files.
Rich (BB code):
Sub ReNameSheet()
    Application.ScreenUpdating = False
    Dim wkbDest As Workbook
    Const strPath As String = "M:\DAILY REVENUE REVIEW\GARTH JOURNAL ENTRIES\TVM CC JE DETAIL FY 2022\12. JUN 2022\"
    ChDir strPath
    strExtension = Dir(strPath & "*.xlsx")
    Do While strExtension <> ""
        Set wkbDest = Workbooks.Open(strPath & strExtension)
        Sheets("WELLS FARGO vs INTERNAL").Name = "CHASE BANK vs INTERNAL"
        Application.DisplayAlerts = False
        ActiveWorkbook.Close True
        Application.DisplayAlerts = True
        strExtension = Dir
    Loop
    Application.ScreenUpdating = True
End Sub
Thanks for the quick reply. I am not having any luck getting the code to run. Does it matter to what workbook the code is inserted? I have tried using the "06-01-2022 TVM..." file and creating the macro by navigating to >VIEW>MACRO>CREATE and also by inserting the MACRO in one of the tabs under the view code option. To test the code for only JUNE workbooks, I have changed the path as you indicated to "M:\DAILY REVENUE REVIEW\GARTH JOURNAL ENTRIES\TVM CC JE DETAIL FY 2022\12. JUN 2022". I have confirmed that all are "xlsx" files. Attached is a screen shot of the directory. I have also changed the code to reflect the correct sheet name and what it should be changed to. I am also getting an error message indicating that the VBA code cannot be saved to a macro free workbook. do the files need to be .xlsm rather than .xlsx? Appreciate your additional insights.
 

Attachments

  • DIRECTORY.JPG
    DIRECTORY.JPG
    177.5 KB · Views: 3
  • Tab name.JPG
    Tab name.JPG
    11.7 KB · Views: 4
Upvote 0
You can place the macro in a regular module in a new, blank workbook and run it from there. Don't place it in the sheet code module by using the view code option. If you save the file with the macro, it must be saved as a macro-enabled file which will give it an "xlsm" extension. Does the macro open the JUNE workbooks? Are you getting any other errors?
 
Upvote 0
Thanks so much! Your original solution worked perfectly. I missed a space in the path name. You are the best!
 
Upvote 0
You are very welcome. :)
 
Upvote 0

Forum statistics

Threads
1,214,583
Messages
6,120,383
Members
448,955
Latest member
BatCoder

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