Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default Howto declare and fill a custom collection of worksheets ?

In the Excel object model we have the built-in collections Worksheets
and Sheets.
I like to create a custom collection of worksheets which will contain
only a sub set of these collections.
Can someone help me how I have to declare such a custom collection and
how I can add sheets to it.
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default Howto declare and fill a custom collection of worksheets ?

I figured it out myself.

Sub WorksheetCollectioTest()

Dim wslist As New Collection

wslist.Add Worksheets("Sheet1")
wslist.Add Worksheets("Sheet2")

Dim ws As Worksheet

For Each ws In wslist
Debug.Print ws.Name
Next ws

End Sub
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default Howto declare and fill a custom collection of worksheets ?

Is it somehow possible to create a specific Worksheets collection
rather than a generic collection in order to get access to built-in
methods and properties fro the worksheets collection?

In excel 2007 this code creates an error 13 (type mismatch) for the
set command.

Dim wsColl As Worksheets
Set wsColl = ActiveWorkbook.Worksheets

Anyone an idea how I can create a custom Worksheets collection with
the same methods as the built-in Worksheets collection?

  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default Howto declare and fill a custom collection of worksheets ?

Worksheets is the collection of worksheets in the active workbook, so using...
Worksheets(3) gives you access to the properties and methods of the third sheet in the workbook.

If you want to declare an object then...
Dim wsColl as Sheets
Set wsColl = Worksheets
wsColl(3) ' same as Worksheets(3)

If you want only specific worksheets then...
Dim wsColl As Sheets
Set wsColl = Worksheets(Array("Sheet1", "Sheet2", "Sheet4"))
(Note that here, wsColl(3) is Sheet4 - which could be anywhere in the workbook)

Also, see ActiveWindow.SelectedSheets
--
Jim Cone
Portland, Oregon USA .
http://www.mediafire.com/PrimitiveSoftware .
(free and commercial excel programs)




"minimaster"
wrote in message
...
Is it somehow possible to create a specific Worksheets collection
rather than a generic collection in order to get access to built-in
methods and properties fro the worksheets collection?

In excel 2007 this code creates an error 13 (type mismatch) for the
set command.

Dim wsColl As Worksheets
Set wsColl = ActiveWorkbook.Worksheets

Anyone an idea how I can create a custom Worksheets collection with
the same methods as the built-in Worksheets collection?



  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,549
Default Howto declare and fill a custom collection of worksheets ?

Correction...
Worksheets(3) gives you access to the properties and methods of the third sheet in the workbook.
-should read-
Worksheets(3) gives you access to the properties and methods of the third worksheet in the
workbook.
---
Jim Cone




  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 73
Default Howto declare and fill a custom collection of worksheets ?

Thx a lot. Declaring the object wsColl "as Sheets" does the trick.
Is it a bug that I can't declare it "as Worksheets" collection?
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
How can I check a collection (e.g. worksheets) collection to be empty? Michiel via OfficeKB.com Excel Programming 2 March 25th 10 02:22 PM
howto put the same header on all worksheets of workbook lemorse Excel Discussion (Misc queries) 6 September 19th 09 10:37 PM
Fill an Array or Collection without knowing the UBound RyanH Excel Programming 5 November 5th 08 04:03 PM
Custom Worksheet Collection ExcelMonkey Excel Programming 1 January 28th 08 04:28 AM
Collection custom functions as asn addin FARAZ QURESHI Excel Discussion (Misc queries) 2 December 29th 07 09:17 PM


All times are GMT +1. The time now is 05:26 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"