Rename Worksheet Tab as File Name Using a Macro

C

Cue

Hello,

I am trying to rename a worksheet tab using the name of the workbook. Each
code I've tried does not work. Does anybody have a simple macro to accomplish
this?

Thanks.
 
C

CLR

Sub RenameSheet()
Dim myname
myname = ThisWorkbook.Name
ActiveSheet.Select
ActiveSheet.Name = myname
Range("A1").Select
End Sub

Vaya con Dios,
Chuck, CABGx3
 
C

Cue

Great! Thanks to both of you for your assistance.

One thing i did not account for... Is there a way rename the tab with the
filename with the ".xls"?
 
F

FSt1

hi
now you will have to use variables.
Sub nametab()
Dim s As String
Dim ss As String
s = ActiveWorkbook.Name
ss = Left(s, Len(s) - 4)
Sheets("Sheet1").Name = ss
End Sub

regards
FSt1
 
×

מיכ×ל (מיקי) ×בידן

I would suggest to try the following code.
1) It will work, as expected, in "Excel 2007 and 2010"
2) It may be run from within a Module and it will rename the Active Sheet at
that moment.
There is alao another "workaround" by checking the Excels version and then
cut-off 4 or 5 characters from the end.
 
C

Cue

Thanks everyone! All your solutions worked!

I found this similar to CLR solution:

Sheets("Sheet2").Name = Replace(ActiveWorkbook. Name, ".xls", "")

Thanks again everyone for your help!
 
C

Cue

Thanks everyone. Of course, all of your solutions worked. Now I have to
decide which one to use.

Thanks again to all of you!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top