Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default ActiveSheet.CodeName?

I'm trying to read the codename of a newly added worksheet, but for some
reason it keeps returning an empty string!


I've tried:

WS_CodeName = WB.Worksheets.Add.CodeName

and also

WB.Worksheets.Add
WS_CodeName = ActiveSheet.CodeName

and even

WB.Worksheets.Add
Set WS = ActiveSheet
WS_CodeName = WS.CodeName

No matter what, it keeps returning an empty string!


What am I doing wrong?!?


TIA


  #2   Report Post  
Posted to microsoft.public.excel.programming
mp mp is offline
external usenet poster
 
Posts: 70
Default ActiveSheet.CodeName?


"Charlotte E" wrote in message
...
I'm trying to read the codename of a newly added worksheet, but for some
reason it keeps returning an empty string!


I've tried:

WS_CodeName = WB.Worksheets.Add.CodeName

and also

WB.Worksheets.Add
WS_CodeName = ActiveSheet.CodeName

and even

WB.Worksheets.Add
Set WS = ActiveSheet
WS_CodeName = WS.CodeName

No matter what, it keeps returning an empty string!


What am I doing wrong?!?


TIA


dunno, try this...

Sub test()
Dim owb As Workbook
Set owb = ActiveWorkbook
Dim oWs As Worksheet
Set oWs = owb.Sheets.Add

MsgBox oWs.Name
MsgBox "(" & oWs.CodeName & ")"

End Sub

works here
hth
mark


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 203
Default ActiveSheet.CodeName?

"mp" wrote in message
...

"Charlotte E" wrote in message
...
I'm trying to read the codename of a newly added worksheet, but for
some reason it keeps returning an empty string!


I've tried:

WS_CodeName = WB.Worksheets.Add.CodeName

and also

WB.Worksheets.Add
WS_CodeName = ActiveSheet.CodeName

and even

WB.Worksheets.Add
Set WS = ActiveSheet
WS_CodeName = WS.CodeName

No matter what, it keeps returning an empty string!


What am I doing wrong?!?


TIA


dunno, try this...

Sub test()
Dim owb As Workbook
Set owb = ActiveWorkbook
Dim oWs As Worksheet
Set oWs = owb.Sheets.Add

MsgBox oWs.Name
MsgBox "(" & oWs.CodeName & ")"

End Sub

works here
hth
mark




Is it possible there's a timing issue here and OP's code is accessing
the codename property before it's been initialized? If that's the case
the msgbox would mask the issue.

What version of Excel?

--
Clif McIrvin

(clare reads his mail with moe, nomail feeds the bit bucket :-)


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,514
Default ActiveSheet.CodeName?

Clif McIrvin presented the following explanation :
"mp" wrote in message
...

"Charlotte E" wrote in message
...
I'm trying to read the codename of a newly added worksheet, but for some
reason it keeps returning an empty string!


I've tried:

WS_CodeName = WB.Worksheets.Add.CodeName

and also

WB.Worksheets.Add
WS_CodeName = ActiveSheet.CodeName

and even

WB.Worksheets.Add
Set WS = ActiveSheet
WS_CodeName = WS.CodeName

No matter what, it keeps returning an empty string!


What am I doing wrong?!?


TIA


dunno, try this...

Sub test()
Dim owb As Workbook
Set owb = ActiveWorkbook
Dim oWs As Worksheet
Set oWs = owb.Sheets.Add

MsgBox oWs.Name
MsgBox "(" & oWs.CodeName & ")"

End Sub

works here
hth
mark




Is it possible there's a timing issue here and OP's code is accessing the
codename property before it's been initialized? If that's the case the
msgbox would mask the issue.

What version of Excel?


Clif,
Excel assigns the CodeName when the sheet is inserted/copied. Both Name
and CodeName can be accessed right away!

--
Garry

Free usenet access at http://www.eternal-september.org
ClassicVB Users Regroup! comp.lang.basic.visual.misc


  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 420
Default ActiveSheet.CodeName?

It's a bug in excel.

If you're testing and you have the VBE open, you'll see the codename assigned
right away. But if the VBE is closed (and never opened??? I forget the
details), then you won't see the codename until you try to do something with it.

I did go to google to search for the fix and found this:
https://groups.google.com/group/micr....*&hl=en&pli=1

or
http://is.gd/B1yFfz

Chip Pearson posted one fix, but I don't recall if that was the easiest way.
You may want to look through google to find a better method.



On 03/09/2011 12:06, Charlotte E wrote:
I'm trying to read the codename of a newly added worksheet, but for some
reason it keeps returning an empty string!


I've tried:

WS_CodeName = WB.Worksheets.Add.CodeName

and also

WB.Worksheets.Add
WS_CodeName = ActiveSheet.CodeName

and even

WB.Worksheets.Add
Set WS = ActiveSheet
WS_CodeName = WS.CodeName

No matter what, it keeps returning an empty string!


What am I doing wrong?!?


TIA



--
Dave Peterson


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default ActiveSheet.CodeName?

Thanks for all your suggestions :-)

Thanks to Ron and GS, I found a workaround, since the only real issue
between 'Name' and 'CodeName' is the number - which was a minor issue for me
:-)

Once again, thanks guys - you're the best :-)

CE


"Charlotte E" wrote in message
...
I'm trying to read the codename of a newly added worksheet, but for some
reason it keeps returning an empty string!


I've tried:

WS_CodeName = WB.Worksheets.Add.CodeName

and also

WB.Worksheets.Add
WS_CodeName = ActiveSheet.CodeName

and even

WB.Worksheets.Add
Set WS = ActiveSheet
WS_CodeName = WS.CodeName

No matter what, it keeps returning an empty string!


What am I doing wrong?!?


TIA




  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,934
Default ActiveSheet.CodeName?

since the only real issue between 'Name' and 'CodeName'
is the number - which was a minor issue for me


Which number are you talking about? I ask because you may not realize that
both the sheet's name AND its code name can be changed. Go into the VB
editor (press ALT+F11) and click on one of the sheets listed in the Project
Window (press CTRL+R if it is not visible), then look at the Properties
Window (press F4 if it is not visible)... the first item in the Properties
list is (Name)... the word Name with parentheses around it... that is the
Code Name... further down the list is the work Name (with no parentheses
around it)... that is the Sheet Name... both of these can be changed by the
user if so desired.

Rick Rothstein (MVP - Excel)

  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 38
Default ActiveSheet.CodeName?

I know :-)

And that was the purpose of my code - to rename the codename to the proper
locale - thus actually not needing the number of the sheet...

CE



"Rick Rothstein" wrote in message
...
since the only real issue between 'Name' and 'CodeName'
is the number - which was a minor issue for me


Which number are you talking about? I ask because you may not realize that
both the sheet's name AND its code name can be changed. Go into the VB
editor (press ALT+F11) and click on one of the sheets listed in the
Project Window (press CTRL+R if it is not visible), then look at the
Properties Window (press F4 if it is not visible)... the first item in the
Properties list is (Name)... the word Name with parentheses around it...
that is the Code Name... further down the list is the work Name (with no
parentheses around it)... that is the Sheet Name... both of these can be
changed by the user if so desired.

Rick Rothstein (MVP - Excel)



Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Codename not set BigJimmer Excel Programming 3 February 27th 10 04:49 AM
Codename not set BigJimmer Excel Programming 2 October 6th 09 06:19 PM
Use a password in VBA ActiveSheet.protect & ActiveSheet.unprotect? Jim K. Excel Programming 2 June 2nd 08 08:09 PM
Copying new activesheet after other activesheet is hidden? Simon Lloyd[_790_] Excel Programming 1 June 20th 06 10:02 AM
codename help Gary Keramidas Excel Programming 14 October 31st 05 12:32 AM


All times are GMT +1. The time now is 05:48 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"