#1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 89
Default Codenames

Hello,
I am trying to use codenames of sheets to track sheet name changes. But
occassionally, I get nothing for a code. For example,

sname = activesheet.name
coden = sheets(sname).codename

coden comes up with nothing. What can cause that?

Thanks,

Bill


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,718
Default Codenames

A sheet module does not exist until it 'appears' in the VBE.

So, run this code with the VBE open and you get a name:

Sub a()
Dim sname, coden
Worksheets.Add
sname = ActiveSheet.Name
coden = Sheets(sname).CodeName
MsgBox coden
End Sub

But run it with the VBE closed and you do not.

--
Jim
"Bill" wrote in message
link.net...
| Hello,
| I am trying to use codenames of sheets to track sheet name changes. But
| occassionally, I get nothing for a code. For example,
|
| sname = activesheet.name
| coden = sheets(sname).codename
|
| coden comes up with nothing. What can cause that?
|
| Thanks,
|
| Bill
|
|


  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Codenames

I took a littlebit different approach.
I made userform1 with textbox1
In Thisworkbook module I put the following code in
the workbook SheetActivate and Deactivate events:

Private Sub Workbook_SheetActivate(ByVal Sh As Object)
UserForm1.Show vbModeless
End Sub

Private Sub Workbook_SheetDeactivate(ByVal Sh As Object)
UserForm1.Hide
End Sub

Then behind the userform module I put your code in 3 events:

Private Sub UserForm_Initialize()
sname = ActiveSheet.Name
coden = Sheets(sname).CodeName
UserForm1.TextBox1.Text = coden
End Sub

Private Sub UserForm_Activate()
sname = ActiveSheet.Name
coden = Sheets(sname).CodeName
UserForm1.TextBox1.Text = coden
End Sub

Private Sub UserForm_Click()
sname = ActiveSheet.Name
coden = Sheets(sname).CodeName
UserForm1.TextBox1.Text = coden
End Sub

Your workbook will need more than one sheet. As you change from sheet
to sheet,
the form will pop up and tell you the codename for the sheet you are
in.
Once you have started it you can click on another workbook and after
clicking once on the form, it will tell you the codenames of that
workbooks sheets as well.

Jim

As you change sheets your form will pop up and tell you the codename.

Bill wrote:
Hello,
I am trying to use codenames of sheets to track sheet name changes. But
occassionally, I get nothing for a code. For example,

sname = activesheet.name
coden = sheets(sname).codename

coden comes up with nothing. What can cause that?

Thanks,

Bill


  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 10,593
Default Codenames

You could try forcing a recompile after naming it

Application.VBE.CommandBars.FindControl(ID:=578).E xecute

--
HTH

Bob Phillips

(replace somewhere in email address with gmail if mailing direct)

"Bill" wrote in message
link.net...
Hello,
I am trying to use codenames of sheets to track sheet name changes. But
occassionally, I get nothing for a code. For example,

sname = activesheet.name
coden = sheets(sname).codename

coden comes up with nothing. What can cause that?

Thanks,

Bill




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
how to use codenames with an addin? Ozz Excel Programming 1 August 31st 06 11:43 AM
using variables in codenames [email protected] Excel Programming 1 April 28th 06 11:30 PM
Excel Worksheet Codenames Alasdair Stirling Excel Programming 6 November 2nd 04 07:33 AM
Excel Worksheet Codenames 2 Alasdair Stirling[_2_] Excel Programming 4 November 1st 04 03:46 PM
Using worksheet codenames dan Excel Programming 0 January 22nd 04 09:46 PM


All times are GMT +1. The time now is 11:39 PM.

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

About Us

"It's about Microsoft Excel"