ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Discussion (Misc queries) (https://www.excelbanter.com/excel-discussion-misc-queries/)
-   -   Rename Worksheet Tab as File Name Using a Macro (https://www.excelbanter.com/excel-discussion-misc-queries/251817-rename-worksheet-tab-file-name-using-macro.html)

Cue

Rename Worksheet Tab as File Name Using a Macro
 
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.
--
Cue

Bob I

Rename Worksheet Tab as File Name Using a Macro
 
Perhaps assign file name to variable, then assign variable to Tab.

Cue wrote:
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.



CLR

Rename Worksheet Tab as File Name Using a Macro
 
Sub RenameSheet()
Dim myname
myname = ThisWorkbook.Name
ActiveSheet.Select
ActiveSheet.Name = myname
Range("A1").Select
End Sub

Vaya con Dios,
Chuck, CABGx3



"Cue" wrote:

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.
--
Cue


FSt1

Rename Worksheet Tab as File Name Using a Macro
 
hi
Sheets("sheet1").Name = ActiveWorkbook.Name

regards
FSt1

"Cue" wrote:

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.
--
Cue


Cue

Rename Worksheet Tab as File Name Using a Macro
 
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"?
--
Cue

Cue

Rename Worksheet Tab as File Name Using a Macro
 
Excuse me...
Is there a way rename the tab with the filename without the ".xls"?
--
Cue


"Cue" wrote:

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"?
--
Cue


Cue

Rename Worksheet Tab as File Name Using a Macro
 
I'll try that. Thanks.
--
Cue


"Bob I" wrote:

Perhaps assign file name to variable, then assign variable to Tab.

Cue wrote:
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.


.


FSt1

Rename Worksheet Tab as File Name Using a Macro
 
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

"Cue" wrote:

Excuse me...
Is there a way rename the tab with the filename without the ".xls"?
--
Cue


"Cue" wrote:

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"?
--
Cue


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

Rename Worksheet Tab as File Name Using a Macro
 
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.
----------------------
Sub NameTab()
ActiveSheet.Name = Left(ActiveWorkbook.Name, InStr(ActiveWorkbook.Name,
".") - 1)
End Sub
--------------
Micky



"Cue" wrote:

I'll try that. Thanks.
--
Cue


"Bob I" wrote:

Perhaps assign file name to variable, then assign variable to Tab.

Cue wrote:
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.


.


Cue

Rename Worksheet Tab as File Name Using a Macro
 
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!
--
Cue


"Cue" wrote:

I'll try that. Thanks.
--
Cue


"Bob I" wrote:

Perhaps assign file name to variable, then assign variable to Tab.

Cue wrote:
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.


.


Cue

Rename Worksheet Tab as File Name Using a Macro
 
Thanks everyone. Of course, all of your solutions worked. Now I have to
decide which one to use.

Thanks again to all of you!
--
Cue



All times are GMT +1. The time now is 07:22 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com