Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel.worksheet.functions
TS TS is offline
external usenet poster
 
Posts: 3
Default How do i assign the ActiveWorkbook.Worksheets to a worksheets object?

doing the commented out stuff below doesn't work. i will be adding
worksheets and so i want to have a collection to start with and just use
those thru my code.

Dim startSheets As Worksheets
Dim sheet As Worksheet


'Set startSheets = ActiveWorkbook.Worksheets

'For Each sheet In ActiveWorkbook.Worksheets
' startSheets.Add (sheet)
'Next

thanks


  #2   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel.worksheet.functions
external usenet poster
 
Posts: 274
Default How do i assign the ActiveWorkbook.Worksheets to a worksheets object?

Change
Dim startSheets As Worksheets
to
Dim startSheets As Sheets

Then Set startSheets = ActiveWorkbook.WorkSheets will work.
The subsequent loop will still throw a run time error - but it isn't
needed since the sheets in question are already part of the collection.
You don't need additional code to initialize startSheets. To verify
this you can replace the loop with

For Each sheet In startSheets
MsgBox sheet.Name
Next

and give it a whirl.

The strange truth behind all this seems to be that there isn't any such
thing as a Worksheets object - even though you can declare a variable
to be one!

Hope that helps

-John Coleman

TS wrote:
doing the commented out stuff below doesn't work. i will be adding
worksheets and so i want to have a collection to start with and just use
those thru my code.

Dim startSheets As Worksheets
Dim sheet As Worksheet


'Set startSheets = ActiveWorkbook.Worksheets

'For Each sheet In ActiveWorkbook.Worksheets
' startSheets.Add (sheet)
'Next

thanks


  #3   Report Post  
Posted to microsoft.public.excel.programming,microsoft.public.excel.worksheet.functions
TS TS is offline
external usenet poster
 
Posts: 3
Default How do i assign the ActiveWorkbook.Worksheets to a worksheets object?

thanks a lot, that worked

"John Coleman" wrote in message
ups.com...
Change
Dim startSheets As Worksheets
to
Dim startSheets As Sheets

Then Set startSheets = ActiveWorkbook.WorkSheets will work.
The subsequent loop will still throw a run time error - but it isn't
needed since the sheets in question are already part of the collection.
You don't need additional code to initialize startSheets. To verify
this you can replace the loop with

For Each sheet In startSheets
MsgBox sheet.Name
Next

and give it a whirl.

The strange truth behind all this seems to be that there isn't any such
thing as a Worksheets object - even though you can declare a variable
to be one!

Hope that helps

-John Coleman

TS wrote:
doing the commented out stuff below doesn't work. i will be adding
worksheets and so i want to have a collection to start with and just use
those thru my code.

Dim startSheets As Worksheets
Dim sheet As Worksheet


'Set startSheets = ActiveWorkbook.Worksheets

'For Each sheet In ActiveWorkbook.Worksheets
' startSheets.Add (sheet)
'Next

thanks




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
Unhide Worksheets Wanna Learn Excel Discussion (Misc queries) 0 November 30th 06 04:38 PM
Keep Format After Merging Worksheets Using CopyFromWorksheet Macro Mark Jackson Excel Discussion (Misc queries) 0 September 25th 05 10:59 PM
Print order of worksheets Stray Doug Excel Discussion (Misc queries) 3 September 21st 05 12:37 AM
Duplicate Worksheets mlofton Excel Discussion (Misc queries) 1 September 7th 05 02:58 PM
Changing a Link Mid-way Across Worksheets Frosty Excel Worksheet Functions 0 August 25th 05 12:03 AM


All times are GMT +1. The time now is 10:15 AM.

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

About Us

"It's about Microsoft Excel"