PC Review


Reply
Thread Tools Rate Thread

Can I refer to a sheet in another book by its codename?

 
 
Michelle
Guest
Posts: n/a
 
      14th May 2010
I want to refer to sheets' codenames that are set up in the active book from
another book (or an add-in)

e.g. MsgBox ActiveWorkbook.SheetCodeNameHere.Cells(6, 2).Value

Can I do that?


M

 
Reply With Quote
 
 
 
 
Rich Locus
Guest
Posts: n/a
 
      14th May 2010
Hello Michelle:
One good way to test syntax is to use the immediate window when you are in
the VBA interface. It will answer syntax questions.

Just enter it in the immediate window as:

MsgBox (ActiveWorkbook.Sheets("YourSheetName").Cells(6, 2).Value)
--
Rich Locus
Logicwurks, LLC


"Michelle" wrote:

> I want to refer to sheets' codenames that are set up in the active book from
> another book (or an add-in)
>
> e.g. MsgBox ActiveWorkbook.SheetCodeNameHere.Cells(6, 2).Value
>
> Can I do that?
>
>
> M
>

 
Reply With Quote
 
Jacob Skaria
Guest
Posts: n/a
 
      14th May 2010
I am not sure I understood your query correctly.

Edit the workbookname as displayed on the caption...Using the workbook
object you can access any open workbook

Sub Macro()
Dim wb As Workbook
Set wb = Workbooks("book1.xls")
MsgBox wb.Worksheets("Sheet1").Range("A1")
End Sub

--
Jacob (MVP - Excel)


"Michelle" wrote:

> I want to refer to sheets' codenames that are set up in the active book from
> another book (or an add-in)
>
> e.g. MsgBox ActiveWorkbook.SheetCodeNameHere.Cells(6, 2).Value
>
> Can I do that?
>
>
> M
>

 
Reply With Quote
 
GS
Guest
Posts: n/a
 
      14th May 2010
Michelle formulated the question :
> I want to refer to sheets' codenames that are set up in the active book from
> another book (or an add-in)
>
> e.g. MsgBox ActiveWorkbook.SheetCodeNameHere.Cells(6, 2).Value
>
> Can I do that?
>
>
> M


Here's a reusable function that will return the sheetname for a sheet
in any open workbook, by passing it a ref to the workbook and the
codename of the sheet.

Function Get_SheetTabName(Wkb As Workbook, CodeName As String) As
String
Dim wks As Worksheet
For Each wks In Wkb.Worksheets
If wks.CodeName = CodeName Then Get_SheetTabName = wks.name: Exit
Function
Next
End Function

Note that the If line is one line, so watch the word wrap.

HTH
Garry


 
Reply With Quote
 
Michelle
Guest
Posts: n/a
 
      14th May 2010
That's more like it! thank you.

M


"GS" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> Michelle formulated the question :
>> I want to refer to sheets' codenames that are set up in the active book
>> from another book (or an add-in)
>>
>> e.g. MsgBox ActiveWorkbook.SheetCodeNameHere.Cells(6, 2).Value
>>
>> Can I do that?
>>
>>
>> M

>
> Here's a reusable function that will return the sheetname for a sheet in
> any open workbook, by passing it a ref to the workbook and the codename of
> the sheet.
>
> Function Get_SheetTabName(Wkb As Workbook, CodeName As String) As String
> Dim wks As Worksheet
> For Each wks In Wkb.Worksheets
> If wks.CodeName = CodeName Then Get_SheetTabName = wks.name: Exit
> Function
> Next
> End Function
>
> Note that the If line is one line, so watch the word wrap.
>
> HTH
> Garry
>
>


 
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
Using a sheet's 'Codename' Michelle Microsoft Excel Programming 1 31st Jul 2009 07:21 AM
Hide sheet via codename chris_j_adams@hotmail.com Microsoft Excel Programming 3 13th Sep 2006 08:28 PM
How can I refer a particular Sheet in a work book from a word doc =?Utf-8?B?QWpheSAtIFB1YmxpeCwgTGFrZWxhbmQgRkw=?= Microsoft Excel Programming 0 17th Mar 2006 09:05 PM
change sheet codename Gary Keramidas Microsoft Excel Programming 4 5th Mar 2006 12:54 AM
Selecting a sheet by codename =?Utf-8?B?RHIuU2Nod2FydHo=?= Microsoft Excel Programming 3 3rd Sep 2004 02:15 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 04:41 AM.