5. Rename the first one in the order of the workbook in multiple workbooks within one folder
Continue tutorials from the previous web page. In this part of the tutorial, in the third order I will show how we can rename worksheet 'Sheet1' in the workbook name if we have multiple workbooks that are in the same folder. If you've been following the tutorial from the start, you've seen that I've created a template.xlsm workbook that contains traffic information. The first in the order of 'Sheet1' is the main worksheet and it must have the name of the workbook (Sheet Tab Name).
In this part of the tutorial, see a VBA macro that we will in every Excel file in the same folder, change the name of the first worksheet "Sheet1" in the name of the workbook. All workbooks are in the same folder. In the previous tutorial, you may have noticed that I have created multiple workbooks in the 'A' column. We continue with the renaming of the first worksheet (Worksheet that has the first position in workbook).
Copy this VBA macro to a VBA Standard Module1 with some newly opened workbook. Start it and notice that all the first worksheets that had the SheetTabName 'Sheet1' were renamed in the name, from the workbook name.
'published by www.ic-ims.com
'published by VoG
Dim MyFolder As String
Dim MyFile As String
Dim wbname As String
MyFolder = "C:\Temp\ccc\" 'define folder - change to suit
MyFile = Dir(MyFolder & "\*.xlsm") ' format file
'Optimize Macro Speed
Application.ScreenUpdating = False
Application.EnableEvents = False
Do While MyFile <> ""
Workbooks.Open Filename:=MyFolder & "\" & MyFile
wbname = Left(.Name, InStr(.Name, ".") - 1)
.Sheets(1).Name = wbname 'rename this Worksheet on 1st position
MyFile = Dir
'Reset Macro Optimization Settings
Application.EnableEvents = True
Application.ScreenUpdating = True
'Message Box when tasks are completed
MsgBox "Task Completed!"
After running VBA macros, wait a few minutes for a message to appear that the task is complete (Task Completed!). I applied this VBA macro to 100 Excel files. This went on for 1-2 minutes.
Now our individual workbook looks like the picture below.
The next step will be to delete a specific 'Sheet Tab Name' in multiple workbooks in the same folder. In this case, 'Sheet5' should be removed from each workbook in the same folder. This workbook does not need us anymore. He was here only temporarily and through it we have created multiple workbooks named with the names in the list in the 'A' column.
List all topics related to complete tutorials
- Creating Top Folders and Sub Folders in One Step
- How to copy a workbook 100 times and create multiple workbooks from the list in the 'A' column
- Rename the first in the order of the worksheet, in multiple workbooks in the same folder
- How to remove the last Worksheet in multiple Workbooks in the same folder
- How to remove a particular VBA module in multiple workbooks in the same folder
- How to save all workbooks as values without formulas in all sub-folders
Click to continue tutorials: ------ >>>>>> The next part of the tutorial Item 4 from list above