OK so, I know I can do this:
Dim ws as worksheet
Set ws = thisworkbook.worksheets("Sheet1")
and then do my fancy stuff with the ws
worksheet object
I also know I can Dim wss as worksheets
and that using worksheets("Sheet1")
returns the worksheet object. So why doesn't the following work?
Dim wss as worksheets
Dim ws as worksheet
Set wss = thisworkbook.worksheets
Set ws = wss("Sheet1")
I've also tried:
Dim wss as worksheets
Dim ws as worksheet
Set ws = thisworkbook.wss("Sheet1")
but the latter just looks like I'm trying to rename/shorten "worksheets" which seems totally wrong. I'm trying to get the worksheets of a workbook in to one worksheets object called wss. This is more about trying to understand the heirachy than anything but for functional purposes I'm trying to get wss to encompass all worksheets from workbook x so I could just do ws = wss(1)
instead of saying set ws = wb.worksheets(1)
Is that even possible or am I misunderstanding the worksheets/ worksheet relationship?
Worksheets
returns the worksheets collection, which I thought'd be fine since I'm not interested in charts. I just wanted to harness the workbook.worksheets collection with a worksheets object. I think I'm missing something simple so thought I'd see what this forum has on offer! I see the most creative code and/or simple explanations on here (compared to official documentation). – RoblesSheets
andWorksheets
properties you'll see that they both return aSheets
object. – ArarobaWorksheets
would return aSheets
collection instead of just aWorksheets
collection. Thanks for clarifying. – RoblesSheets
collection ofWorksheets
only. I think I've had enough of VBA for today :D – Robles