![]() If you ignore the ActiveWorkbook object while refering any other object like sheet, range or chart, VBA will treat the ActiveWorkbook as the current Workbook by default. ActiveWorkbook VBA object is very usefull while automating tasks and working on currently active Excel WorkBook in the active workbook window. We can refer the currently activated Excel Workbook using Excel VBA ActiveWorkbook object. ThisWorkbook.Activate 'This will activate "MyProjects1.xlsm 'You can come back to activate the currently macro running workbook 'Lets say you have written this macro in "MyProjects1.xlsm ![]() Let’s say you have your macros in “MyProjects1.xlsm” and you have opened multiple workbooks say Book2.xlsx, Book3.xlsx, Book4.xlsx, and you can deal with any workbook and come back to your original workbook with the currently running code by just referring to ThisWorkbook Object. This will be very useful while dealing with the multiple workbooks. Please see the below VBA codes to activate a currently running macro workbook. VBA Activate Workbook – ThisWorkbook:Example 2 In this example we are activating a workbook 2 in the currently opened workbooks collection. Please see the below VBA codes to activate a Workbook using workbook number. VBA Activate Workbook – with Number:Example 2 In this example we are activating a workbook named “Project1”. Please see the below VBA codes to activate a Workbook. ThisWorkbook.Activate VBA Activate Workbook – with Name:Example 1 ‘And you can use Thisworkbook.Activate method to activate the workbook with the current procedure/macro
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |