The following VBA procedure demonstrates how to activate a workbook that is already open. This is especially useful when multiple workbooks are open and you want to make sure that further actions are performed in a specific one:
Sub ActivateWorkbook() ThisWorkbook.Activate MsgBox ActiveWorkbook.Name End Sub
Explanation:
This procedure uses the Activate() method of the Workbook object. In this case, it calls ThisWorkbook.Activate, which activates the workbook that contains this very VBA code.
When a workbook is activated, Excel brings it into focus—making it the currently selected and interactive file. This is important when automating tasks across multiple open workbooks and you want to ensure that subsequent operations (such as writing data, inserting sheets, or saving files) affect the correct one.
To confirm the activation, the procedure then displays the name of the currently active workbook using ActiveWorkbook.Name.