VBA to rename Tab by merging file name

excelsishya

Board Regular
Joined
Jul 25, 2010
Messages
107
Hi all ,

Could anyone provide code which renames tabs in all excel file in folder by adding last 4 letter of file name to tab.

Have excel file with jan feb etc tab name.file name is income statement 2008.xls.

after running code desired output jan2009 feb2009.

I am using excel 2007.

Also after naming each of tab is it possible move all tabs to master file.

Thanks in advance.
 

Excel Facts

Can you sort left to right?
To sort left-to-right, use the Sort dialog box. Click Options. Choose "Sort left to right"
try this code
it is working just with open workbook
Code:
Sub Test()
Dim ws As Worksheet
For Each ws In Sheets
    ws.Name = ws.Name & Mid(ActiveWorkbook.Name, Len(ActiveWorkbook.Name) - 8, 4)
Next ws
End Sub
 
Upvote 0
Yahya thanks for code it works fine.

Also if there is code to do same thing without opening file please provide it.


if file has all 12 months tabs , then it becomes easy to do opening running code.

in some cases i also come across file with only 1 month tab in such case i have to open 36-48 tabs run code .for such cases i am looking for 2 type of code.
 
Upvote 0

Forum statistics

Threads
1,223,231
Messages
6,170,884
Members
452,364
Latest member
springate

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