PC Review


Reply
Thread Tools Rate Thread

How do i assign the ActiveWorkbook.Worksheets to a worksheets object?

 
 
TS
Guest
Posts: n/a
 
      22nd Dec 2006
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 With Quote
 
 
 
 
John Coleman
Guest
Posts: n/a
 
      23rd Dec 2006
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 With Quote
 
TS
Guest
Posts: n/a
 
      27th Dec 2006
thanks a lot, that worked

"John Coleman" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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 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 activeworkbook.worksheets SangelNet Microsoft Excel Programming 6 10th Dec 2008 04:16 PM
How do i assign the ActiveWorkbook.Worksheets to a worksheets object? TS Microsoft Excel Worksheet Functions 2 27th Dec 2006 02:49 PM
Adding a sheets name to the worksheets that are copied over from an addin file to the activeworkbook KimberlyC Microsoft Excel Programming 2 7th May 2005 04:10 AM
For Each wks In ActiveWorkbook.Worksheets bar a specific one? =?Utf-8?B?UGFuayBNZWh0YQ==?= Microsoft Excel Misc 4 30th Mar 2005 04:53 PM
Populating a listbox will a certain cell on multiple worksheets in the activeworkbook KimberlyC Microsoft Excel Programming 2 16th Mar 2005 12:49 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 02:43 AM.