Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 37
Default Codename not set

I use the worksheet codename extensively throughout my add-ins. However at
times I get errors because the codemame is not initialized at the point in
the code where it is being referenced.

For example, if I add something like this to my code....

sub Test (ws as Worksheet)

dim str as string

str = ws.CodeName

if str = "" then
debug.print "Missing Codename"
else
debug.print "CodeName = " & ws.Codename
end sub

I sometimes will get "Missing Codename", and other times (for the same
worksheet), it returns the code name. If I try stepping through the code, it
will always return a value for CodeName.

I have narrowed the occurrence of the problem down to being when the
worksheet uses the default code name (Sheet#) and the code is run either
during the workbook open event, or is run using a worksheet that was just
added to the workbook.

Any ideas on how to resolve this problem?

This happens in both Exccel 2000 and 2003.


  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default codename not set

I found the way to find out the sheet codename without going to VBAProject below is the code for your reference

Public Function sheet_codename() As String

Dim sht As Integer
'Dim sht_cdname As String
Dim actual_shtnm As String, temp_shtnm As String

For sht = 2 To Application.ActiveWorkbook.VBProject.VBComponents. Count
actual_shtnm = Application.ActiveWorkbook.ActiveSheet.Name
'ss = Application.ActiveWorkbook.VBProject.VBComponents( sht).Name
temp_shtnm = Application.ActiveWorkbook.VBProject.VBComponents( sht).Properties("name").Value
If Application.ActiveWorkbook.VBProject.VBComponents( sht).Type = 100 Then
If actual_shtnm = temp_shtnm Then
sheet_codename = Application.ActiveWorkbook.VBProject.VBComponents( sht).Name

End If
End If
Next

End Function




BigJimmer wrote:

Codename not set
13-Jan-10

I use the worksheet codename extensively throughout my add-ins. However at
times I get errors because the codemame is not initialized at the point in
the code where it is being referenced.

For example, if I add something like this to my code....

sub Test (ws as Worksheet)

dim str as string

str = ws.CodeName

if str = "" then
debug.print "Missing Codename"
else
debug.print "CodeName = " & ws.Codename
end sub

I sometimes will get "Missing Codename", and other times (for the same
worksheet), it returns the code name. If I try stepping through the code, it
will always return a value for CodeName.

I have narrowed the occurrence of the problem down to being when the
worksheet uses the default code name (Sheet#) and the code is run either
during the workbook open event, or is run using a worksheet that was just
added to the workbook.

Any ideas on how to resolve this problem?

This happens in both Exccel 2000 and 2003.

Previous Posts In This Thread:

On Wednesday, January 13, 2010 9:54 PM
BigJimmer wrote:

Codename not set
I use the worksheet codename extensively throughout my add-ins. However at
times I get errors because the codemame is not initialized at the point in
the code where it is being referenced.

For example, if I add something like this to my code....

sub Test (ws as Worksheet)

dim str as string

str = ws.CodeName

if str = "" then
debug.print "Missing Codename"
else
debug.print "CodeName = " & ws.Codename
end sub

I sometimes will get "Missing Codename", and other times (for the same
worksheet), it returns the code name. If I try stepping through the code, it
will always return a value for CodeName.

I have narrowed the occurrence of the problem down to being when the
worksheet uses the default code name (Sheet#) and the code is run either
during the workbook open event, or is run using a worksheet that was just
added to the workbook.

Any ideas on how to resolve this problem?

This happens in both Exccel 2000 and 2003.

On Friday, February 26, 2010 8:43 AM
Geeta Sonawane wrote:

Sheet code name not set
I found the way to find out the sheet codename without going to VBAProject below is the code for your reference

Public Function sheet_codename() As String

Dim sht As Integer
'Dim sht_cdname As String
Dim actual_shtnm As String, temp_shtnm As String

For sht = 2 To Application.ActiveWorkbook.VBProject.VBComponents. Count
actual_shtnm = Application.ActiveWorkbook.ActiveSheet.Name
'ss = Application.ActiveWorkbook.VBProject.VBComponents( sht).Name
temp_shtnm = Application.ActiveWorkbook.VBProject.VBComponents( sht).Properties("name").Value
If Application.ActiveWorkbook.VBProject.VBComponents( sht).Type = 100 Then
If actual_shtnm = temp_shtnm Then
sheet_codename = Application.ActiveWorkbook.VBProject.VBComponents( sht).Name

End If
End If
Next

End Function


Submitted via EggHeadCafe - Software Developer Portal of Choice
Generic Feed Parsers Redux
http://www.eggheadcafe.com/tutorials...sers-redu.aspx
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 7,247
Default codename not set

The Worksheet object has a CodeName property that returns the code
name of the sheet. E.,g

Dim WS As Worksheet
For Each WS In ThisWorkbook.Worksheets
Debug.Print "Name: " & WS.Name, "CodeName: " & WS.CodeName
Next WS

Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com



On Fri, 26 Feb 2010 05:47:19 -0800, Geeta Sonawane wrote:

I found the way to find out the sheet codename without going to VBAProject below is the code for your reference

Public Function sheet_codename() As String

Dim sht As Integer
'Dim sht_cdname As String
Dim actual_shtnm As String, temp_shtnm As String

For sht = 2 To Application.ActiveWorkbook.VBProject.VBComponents. Count
actual_shtnm = Application.ActiveWorkbook.ActiveSheet.Name
'ss = Application.ActiveWorkbook.VBProject.VBComponents( sht).Name
temp_shtnm = Application.ActiveWorkbook.VBProject.VBComponents( sht).Properties("name").Value
If Application.ActiveWorkbook.VBProject.VBComponents( sht).Type = 100 Then
If actual_shtnm = temp_shtnm Then
sheet_codename = Application.ActiveWorkbook.VBProject.VBComponents( sht).Name

End If
End If
Next

End Function




BigJimmer wrote:

Codename not set
13-Jan-10

I use the worksheet codename extensively throughout my add-ins. However at
times I get errors because the codemame is not initialized at the point in
the code where it is being referenced.

For example, if I add something like this to my code....

sub Test (ws as Worksheet)

dim str as string

str = ws.CodeName

if str = "" then
debug.print "Missing Codename"
else
debug.print "CodeName = " & ws.Codename
end sub

I sometimes will get "Missing Codename", and other times (for the same
worksheet), it returns the code name. If I try stepping through the code, it
will always return a value for CodeName.

I have narrowed the occurrence of the problem down to being when the
worksheet uses the default code name (Sheet#) and the code is run either
during the workbook open event, or is run using a worksheet that was just
added to the workbook.

Any ideas on how to resolve this problem?

This happens in both Exccel 2000 and 2003.

Previous Posts In This Thread:

On Wednesday, January 13, 2010 9:54 PM
BigJimmer wrote:

Codename not set
I use the worksheet codename extensively throughout my add-ins. However at
times I get errors because the codemame is not initialized at the point in
the code where it is being referenced.

For example, if I add something like this to my code....

sub Test (ws as Worksheet)

dim str as string

str = ws.CodeName

if str = "" then
debug.print "Missing Codename"
else
debug.print "CodeName = " & ws.Codename
end sub

I sometimes will get "Missing Codename", and other times (for the same
worksheet), it returns the code name. If I try stepping through the code, it
will always return a value for CodeName.

I have narrowed the occurrence of the problem down to being when the
worksheet uses the default code name (Sheet#) and the code is run either
during the workbook open event, or is run using a worksheet that was just
added to the workbook.

Any ideas on how to resolve this problem?

This happens in both Exccel 2000 and 2003.

On Friday, February 26, 2010 8:43 AM
Geeta Sonawane wrote:

Sheet code name not set
I found the way to find out the sheet codename without going to VBAProject below is the code for your reference

Public Function sheet_codename() As String

Dim sht As Integer
'Dim sht_cdname As String
Dim actual_shtnm As String, temp_shtnm As String

For sht = 2 To Application.ActiveWorkbook.VBProject.VBComponents. Count
actual_shtnm = Application.ActiveWorkbook.ActiveSheet.Name
'ss = Application.ActiveWorkbook.VBProject.VBComponents( sht).Name
temp_shtnm = Application.ActiveWorkbook.VBProject.VBComponents( sht).Properties("name").Value
If Application.ActiveWorkbook.VBProject.VBComponents( sht).Type = 100 Then
If actual_shtnm = temp_shtnm Then
sheet_codename = Application.ActiveWorkbook.VBProject.VBComponents( sht).Name

End If
End If
Next

End Function


Submitted via EggHeadCafe - Software Developer Portal of Choice
Generic Feed Parsers Redux
http://www.eggheadcafe.com/tutorials...sers-redu.aspx

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default Sheet codename

This property is not useful still the VBA code window is not open for that workbook. Through addin we can't get the code name for activeworkbook. so the above solution is require.
you try to add your code in one workbook or addin and find out the sheet codename for new workbook without going in VBA code.



Chip Pearson wrote:

The Worksheet object has a CodeName property that returns the codename of the
26-Feb-10

The Worksheet object has a CodeName property that returns the code
name of the sheet. E.,g

Dim WS As Worksheet
For Each WS In ThisWorkbook.Worksheets
Debug.Print "Name: " & WS.Name, "CodeName: " & WS.CodeName
Next WS

Cordially,
Chip Pearson
Microsoft Most Valuable Professional,
Excel, 1998 - 2010
Pearson Software Consulting, LLC
www.cpearson.com

Previous Posts In This Thread:


Submitted via EggHeadCafe - Software Developer Portal of Choice
Generic Feed Parsers Redux
http://www.eggheadcafe.com/tutorials...sers-redu.aspx
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 2 October 6th 09 06:19 PM
Using a sheet's 'Codename' Michelle Excel Programming 1 July 31st 09 07:21 AM
Codename passing Nigel[_2_] Excel Programming 3 December 10th 07 12:50 PM
VBA codename and codeprotection CoCo Excel Programming 0 August 10th 06 04:46 AM
codename help Gary Keramidas Excel Programming 14 October 31st 05 12:32 AM


All times are GMT +1. The time now is 10:54 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"