Hi All,
My macro uses two workbooks. The first workbook is my main workbook (ThisWorkbook) where the macro runs, and this macro opens another workbook that I use after.
My code is:
Currently I can only run this macro by having no other workbooks open as it locates the second open workbook.
If I have multiple spreadsheets open before running this macro it will pull in data from the incorrect spreadsheet.
Is there a way I can set new_WB to be equal to the next open workbook rather than the second workbook so it locates the correct spreadsheet regardless of how many workbooks I have open?
Thanks.
My macro uses two workbooks. The first workbook is my main workbook (ThisWorkbook) where the macro runs, and this macro opens another workbook that I use after.
My code is:
VBA Code:
Dim new_WB as Workbook
Set new_WB = Workbooks(2)
new_WB.Activate
Currently I can only run this macro by having no other workbooks open as it locates the second open workbook.
If I have multiple spreadsheets open before running this macro it will pull in data from the incorrect spreadsheet.
Is there a way I can set new_WB to be equal to the next open workbook rather than the second workbook so it locates the correct spreadsheet regardless of how many workbooks I have open?
Thanks.