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

Hi All
I have the codenames for various worksheets stored as strings in another
worksheet. How can I assign each sheet to an object?

e.g. If I have the string "myCodeName" which is the codename for one of the
worksheets, and want to assign it to a worksheet object

Dim wSh as Worksheet
Set wSh = ??

TIA
--

Regards,
Nigel




  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 9,101
Default Codename passing

Set wSh = sheets("myCodeName")


"Nigel" wrote:

Hi All
I have the codenames for various worksheets stored as strings in another
worksheet. How can I assign each sheet to an object?

e.g. If I have the string "myCodeName" which is the codename for one of the
worksheets, and want to assign it to a worksheet object

Dim wSh as Worksheet
Set wSh = ??

TIA
--

Regards,
Nigel




  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,600
Default Codename passing

Ah, your other post makes more sense now. You need to loop sheets to find
it.

Try the following, rename your sheet that has the codename Sheet2

Sub test()
Dim res As Long
Dim s$
Dim ws As Worksheet
s = "Sheet2" ' the codename

res = WsFromCodeName(s, ActiveWorkbook, ws)
If res = 1 Then
MsgBox ws.Name
ElseIf res = 2 Then
MsgBox "can't return all codenames"
Else
MsgBox s & " not found"
End If

End Sub

Function WsFromCodeName(ByVal sCodeName As String, _
ByVal wb As Workbook, _
ByRef ws As Worksheet) As Long
Dim s As String
For Each ws In wb.Worksheets
s = ws.CodeName
If s = "" Then
' sheet inserted since last saved
WsFromCodeName = 2
ElseIf s = sCodeName Then
WsFromCodeName = 1
Exit For
End If
Next

End Function

Regards,
Peter T

"Nigel" wrote in message
...
Hi All
I have the codenames for various worksheets stored as strings in another
worksheet. How can I assign each sheet to an object?

e.g. If I have the string "myCodeName" which is the codename for one of

the
worksheets, and want to assign it to a worksheet object

Dim wSh as Worksheet
Set wSh = ??

TIA
--

Regards,
Nigel






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
string to codename rk0909 Excel Discussion (Misc queries) 4 September 25th 08 10:57 PM
CodeName Referencing Help AucklandAssault Excel Programming 3 February 6th 07 04:09 AM
Codename conflict Jim Rech Excel Programming 0 January 22nd 07 04:20 PM
codename help Gary Keramidas Excel Programming 14 October 31st 05 12:32 AM
Worksheet codename Andy Excel Programming 4 December 2nd 03 04:12 PM


All times are GMT +1. The time now is 12:32 AM.

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"