Hey party people,
I am trying to navigate and read data from specific sheets from multiple workbooks using VBA.
When working with a single workbook, I use SheetX.Select often (X = 1, 2, 3... whatever sheet number I'm looking for at the moment) because the tabs change names, move order, or become hidden as the workbook becomes more refined and this method seems to keep my code from breaking, so far.
I also noticed when working with a single workbook with hidden sheets... Sheet13.Select DOES NOT always function equally to Worksheets(13).Activate in terms of activating the proper sheet. It seems the order in which the sheets are placed determines which sheet is opened if you use Activate method, and it will not open strictly based on its Sheet#, could someone expand on this and either confirm or correct my thoughts?
When working with two (or multiple) workbooks, I've only been able to navigate to the secondary workbook and its sheets by using the .Activate method, example is below... But my code is not opening the correct sheet as the observation above as stated, how do I properly extend the quasi-dynamic referencing to activate by sheet# instead of sheet name in the secondary workbook?
I am trying to navigate and read data from specific sheets from multiple workbooks using VBA.
When working with a single workbook, I use SheetX.Select often (X = 1, 2, 3... whatever sheet number I'm looking for at the moment) because the tabs change names, move order, or become hidden as the workbook becomes more refined and this method seems to keep my code from breaking, so far.
I also noticed when working with a single workbook with hidden sheets... Sheet13.Select DOES NOT always function equally to Worksheets(13).Activate in terms of activating the proper sheet. It seems the order in which the sheets are placed determines which sheet is opened if you use Activate method, and it will not open strictly based on its Sheet#, could someone expand on this and either confirm or correct my thoughts?
When working with two (or multiple) workbooks, I've only been able to navigate to the secondary workbook and its sheets by using the .Activate method, example is below... But my code is not opening the correct sheet as the observation above as stated, how do I properly extend the quasi-dynamic referencing to activate by sheet# instead of sheet name in the secondary workbook?
Code:
Dim wkb1, wkb2 As Workbook
Set wkb1 = ThisWorkbook
Workbooks.Open Filename :=MyFolder & "\" & MyFile
Set wkb2 = Workbooks(MyFile)
'This workbook contains hidden tabs, that I would like to remain hidden
wkb2.Worksheets(13).Activate
'opens incorrect sheet. I want Sheet13... this opens Sheet16 which is a tab to the left of Sheet13.
'wkb2.Worksheet(21).Activate 'opens Sheet13... but I assume I need to update this if I hide/unhide or add/delete sheets
'wkb2.Sheets13.Activate Run-time error '438': Object doesn't support this property or method
'wkb2.Sheet13.Select Run-time error '438': Object doesn't support this property or method
'wkb2.Worksheets(13).Select Run-time error '1004': Select method of Worksheet class failed
'Then read and do code on active sheet