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

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
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,224,586
Messages
6,179,711
Members
452,939
Latest member
WCrawford

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