Microsoft Excel Macros

 

VBA Lesson 14: VBA for Excel for Workbooks

To develop a VBA procedure that is triggered by an event relating to the workbook (when you open it, when you save it, when you close it) see the VBA lesson on events.

ThisWorkbook

ThisWorkbook is the workbook within which your VBA procedure runs. So if you write:
ThisWorkbook.Save
The workbook within which your VBA procedure (macro) runs will be saved.

If you want to close the workbook within which your VBA procedure (macro) runs without saving it you will write these two lines of code:
ThisWorkbook.Saved=True
ThisWorkbook.Close

Workbooks and Windows

When you work with two workbooks you will move from one to the other with:
ThisWorkbook.Activate
Windows("theOtherWorkbookName.xls").Activate


Go to the next lesson
Lesson
15 : VBA for Excel for Worksheets


left arrow Back home