The spreadsheet application can have none, one or many workbooks open at one time and each workbook can have one or more worksheets. All of these are part of a straightforward hierarchy:
Workbooks ' all the workbooks in an application
Workbooks.Count ' how many workbooks do we have open
Workbooks(0) ' the first open workbook
Workbooks("myspread") ' the workbook called myspread
Once you've got hold of a workbook, you can examine it's name, count it's worksheets and refer to individual worksheets:
Dim wb, ws
Set wb = Workbooks(0)
MsgBox "Name is " & wb.Name & ", and has " & wb.Worksheets.Count & "worksheets."
Set ws = wb.Worksheets(0) ' or alternatively Set ws = wb.Worksheets("mysheet")
Msg "First worksheet is called: " & ws.Name
There can be only one active (or current) workbook however. Also, there can be only one active sheet and one active cell.
ActiveCell |
Returns the current cell in the current worksheet in the current workbook. |
ActiveSheet |
Current worksheet. |
ActiveWorkbook |
Current workbook. |