PC Review


Reply
Thread Tools Rate Thread

Codename passing

 
 
Nigel
Guest
Posts: n/a
 
      10th Dec 2007
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
(E-Mail Removed)



 
Reply With Quote
 
 
 
 
Joel
Guest
Posts: n/a
 
      10th Dec 2007
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
> (E-Mail Removed)
>
>
>

 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      10th Dec 2007
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" <nigel-(E-Mail Removed)> wrote in message
news:111F76AB-EB81-4E65-BC08-(E-Mail Removed)...
> 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
> (E-Mail Removed)
>
>
>



 
Reply With Quote
 
Nigel
Guest
Posts: n/a
 
      10th Dec 2007
OK thanks, got it!

I need to scan all sheets to find the codename which IDs the relevant sheet

--

Regards,
Nigel
(E-Mail Removed)



"Peter T" <peter_t@discussions> wrote in message
news:(E-Mail Removed)...
> 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" <nigel-(E-Mail Removed)> wrote in message
> news:111F76AB-EB81-4E65-BC08-(E-Mail Removed)...
>> 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
>> (E-Mail Removed)
>>
>>
>>

>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Passing sheet (using codename) to separate sub as optional paramet ker_01 Microsoft Excel Programming 7 2nd Apr 2010 01:13 AM
Codename not set BigJimmer Microsoft Excel Programming 3 27th Feb 2010 04:49 AM
Codename not set BigJimmer Microsoft Excel Programming 2 6th Oct 2009 06:19 PM
Hitman: Codename 47 =?Utf-8?B?QW50c3k0Nw==?= Windows XP Games 2 6th Jun 2006 12:59 AM
codename help Gary Keramidas Microsoft Excel Programming 14 31st Oct 2005 12:32 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 01:33 AM.