Saturday, July 21, 2018

Accessing Workbook via VBA Code

When accessing current workbook:

use ThisWorkBook method

Debug.Print ActiveWorkbook.FullName


When accessing Any open workbook:

use Workbooks("name")

Debug.Print Workbooks("test.xlsx").FullName

Please note: above example will throw script out of range error if workbook is not opened or you mention full path of workbook.

Avoid using ActiveWorkbook and Workbooks(index) 

No comments:

Post a Comment

Autofilter: To filter with macro

Below is very basic macro to define filter on atable which has two columns. Name(Comuln A) and Dept(Column B). Function will filter all emp...