Selecting


ThisWorkbook or ActiveWorkbook ?

ActiveWorkbook refers to the workbook that is currently in the active window.
ThisWorkbook refers to the workbook where the code is actually running from.

ThisWorkbook.Path 

No matter where the workbook is saved ThisWorkbook.Path always returns the current location of the file.


Activating and Selecting

Workbooks("Wbk1.xls").Activate 

Can be used if the workbook is new and has not yet been saved.

Workbooks("Book3").Activate 
Workbooks("Book3.xls").Activate

assuming that the workbook has been saved

Workbooks.Item(2).Activate 
Workbooks(2).Activate

This refers to the workbook that contains the code.

ThisWorkbook. 

objWorkbook.Activate 

List all the open workbooks

For Each oWbk In Application.Workbooks 
    Debug.Print oWbk.Name
Next oWbk


© 2024 Better Solutions Limited. All Rights Reserved. © 2024 Better Solutions Limited TopPrevNext