Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Excel / Programming / December 2007

Tip: Looking for answers? Try searching our database.

Codename passing

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Nigel - 10 Dec 2007 11:09 GMT
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
Signature


Regards,
Nigel
nigelnospam@9sw.co.uk

Joel - 10 Dec 2007 12:01 GMT
Set wSh = sheets("myCodeName")

> Hi All
> I have the codenames for various worksheets stored as strings in another
[quoted text clipped - 7 lines]
>
> TIA
Peter T - 10 Dec 2007 12:09 GMT
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

> Hi All
> I have the codenames for various worksheets stored as strings in another
[quoted text clipped - 7 lines]
>
> TIA
Nigel - 10 Dec 2007 12:50 GMT
OK thanks, got it!

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

Signature

Regards,
Nigel
nigelnospam@9sw.co.uk

> Ah, your other post makes more sense now. You need to loop sheets to find
> it.
[quoted text clipped - 50 lines]
>>
>> TIA
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.