Renaming excel worksheets back

March 11, 2009 at 06:00:18
Specs: Excel
I have some excel files that have been given names to the worksheets. Worksheets are named "3Com" "BureauVanD" "Acer" etc. etc. But I need to make some programming and I would like to give the worksheet their default names, like sheet1 sheet2 sheet3 etc. How can I do this? I have to work with hundreds of these excel files so I cannot do it manually... If someone can please help me!!

See More: Renaming excel worksheets back

Report •

March 11, 2009 at 09:35:55
First off, I'm not sure why "programming" would force you to rename the sheets. You can refer to a sheet in VBA without caring (or even knowing) what it says on the tab.

Let's says Sheet1 has been named One and Sheet2 has been named Two.

In VBA you can refer to these sheets as Sheets("One") and Sheets("Two") or as Sheets(1) and Sheets(2) where the 1 and 2 depict the order of the sheets in the workbook. If you refer to the sheets by number, you shouldn't have to care what it says on the Tab.

That said, if you really want to rename the sheets back their original names, use this code. It refers to each sheet by it's number and uses the same variable to build the sheet name.

Sub OldNames()
 For Sht = 1 To Sheets.Count
  Sheets(Sht).Name = "Sheet" & Sht
End Sub

Report •

March 11, 2009 at 10:18:14
First, thanks a lot, really. Maybe this was an stupid question for a regular user of VBA. What I need to do is not easy to explain since I need to do a lot of work with hundreds of files each one with a hundred worksheets. Probably what I'm doing is silly, cause i'm not an expert, not even a regular user of VBA, but I have already found a perfect solution for my problem using the original names of the sheets. Your code worked perfectly and it helped me a lot, thanks again!

Report •

Related Solutions

Ask Question