PC Review


Reply
 
 
CTSCampbell@gmail.com
Guest
Posts: n/a
 
      19th Oct 2006
Hi all,

I was wondering if there is anyway to reference a sheet by codename
that is in a different workbook than the one in which your macro
resides. The reason is, I need to access specific series of sheets
arbitrary in number in a series of other workbooks, the sheet names are
a character string as in "X sheet 1 of Y" Where Y is unknown; however,
the codenames are an incremented number, which would be much easier to
deal with.

Thanks for you help in advance,
Chris

 
Reply With Quote
 
 
 
 
=?Utf-8?B?VG9tIE9naWx2eQ==?=
Guest
Posts: n/a
 
      19th Oct 2006
for a codename of Sheet2 for example: (the tab name is not sheet2)

dim s as String, sh as worksheet
Dim bk as Workbook
set bk = Workbooks("OtherWorkbookName.xls")
s = bk.vbProject.VBComponents("Sheet2").Properties("Name").Value
set sh = bk.Worksheets(s)

in xl2003, these are the properties of a worksheet: (and values for this
specifc sheet as an example):

1 Application
2 Creator 1480803660
3 Parent
4 CodeName Sheet2
5 _CodeName Sheet2
6 Index 2
7 Name MDMS_20061018_FY09_13
8 Next
9 OnDoubleClick
10 OnSheetActivate
11 OnSheetDeactivate
12 PageSetup
13 Previous
14 ProtectContents False
15 ProtectDrawingObjects False
16 ProtectionMode False
17 ProtectScenarios False
18 Visible -1
19 Shapes
20 TransitionExpEval False
21 AutoFilterMode True
22 EnableCalculation True
23 Cells
24 CircularReference
25 Columns
26 ConsolidationFunction -4157
27 ConsolidationOptions
28 ConsolidationSources
29 DisplayAutomaticPageBreaks False
30 EnableAutoFilter False
31 EnableSelection 0
32 EnableOutlining False
33 EnablePivotTable False
34 FilterMode True
35 Names
36 OnCalculate
37 OnData
38 OnEntry
39 Outline
41 Rows
42 ScrollArea
43 StandardHeight 12.75
44 StandardWidth 8.43
45 TransitionFormEntry False
46 Type -4167
47 UsedRange
48 HPageBreaks
49 VPageBreaks
50 QueryTables
51 DisplayPageBreaks False
52 Comments
53 Hyperlinks
54 _DisplayRightToLeft False
55 AutoFilter
56 DisplayRightToLeft False
57 Scripts
58 Tab
59 MailEnvelope
60 CustomProperties
61 SmartTags
62 Protection
63 ListObjects

code to get them (in the immediate window)

Sub abc()
On Error Resume Next
i = 1
For Each pr In
Workbooks("MDMS_20061018_FY09_13.xls").VBProject.VBComponents("Sheet2").Properties
Debug.Print i, pr.Name, pr.Value
i = i + 1
Next
On Error GoTo 0
End Sub



--
Regards,
Tom Ogilvy


"(E-Mail Removed)" wrote:

> Hi all,
>
> I was wondering if there is anyway to reference a sheet by codename
> that is in a different workbook than the one in which your macro
> resides. The reason is, I need to access specific series of sheets
> arbitrary in number in a series of other workbooks, the sheet names are
> a character string as in "X sheet 1 of Y" Where Y is unknown; however,
> the codenames are an incremented number, which would be much easier to
> deal with.
>
> Thanks for you help in advance,
> Chris
>
>

 
Reply With Quote
 
Peter T
Guest
Posts: n/a
 
      19th Oct 2006
Perhaps you could loop worksheet names until you find your hard-coded
CodeName. Or store all in a collection, eg

Dim mColWSnames As Collection

Sub SetWScollection(wb As Workbook)
Dim ws As Worksheet

Set mColWSnames = New Collection
For Each ws In wb.Worksheets
mColWSnames.Add ws.Name, ws.CodeName
Next

End Sub

Sub Test()
Dim sCodename As String
Dim ws As Worksheet

sCodename = ActiveWorkbook.Worksheets(2).CodeName 'normally already known
ActiveWorkbook.Worksheets(2).Name = "NewName"
SetWScollection ActiveWorkbook

Set ws = ActiveWorkbook.Worksheets(mColWSnames("Sheet2"))
MsgBox ws.Name, , sCodename
End Sub

Regards,
Peter T


<(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> Hi all,
>
> I was wondering if there is anyway to reference a sheet by codename
> that is in a different workbook than the one in which your macro
> resides. The reason is, I need to access specific series of sheets
> arbitrary in number in a series of other workbooks, the sheet names are
> a character string as in "X sheet 1 of Y" Where Y is unknown; however,
> the codenames are an incremented number, which would be much easier to
> deal with.
>
> Thanks for you help in advance,
> Chris
>



 
Reply With Quote
 
CTSCampbell@gmail.com
Guest
Posts: n/a
 
      19th Oct 2006
Tom,

Thanks for your help and prompt response.

Chris

 
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
Sheet CodeNames =?Utf-8?B?S2FyZW41Mw==?= Microsoft Excel Programming 7 13th Sep 2007 05:26 PM
Codenames Bill Microsoft Excel Programming 3 8th Sep 2006 06:59 PM
how to use codenames with an addin? =?Utf-8?B?T3p6?= Microsoft Excel Programming 1 31st Aug 2006 11:43 AM
using variables in codenames mars1968@gmail.com Microsoft Excel Programming 1 28th Apr 2006 11:30 PM
Using worksheet codenames =?Utf-8?B?ZGFu?= Microsoft Excel Programming 0 22nd Jan 2004 09:46 PM


Features
 

Advertising
 

Newsgroups
 


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