ThisWorkbook Property

Applies To

Application Object.

Description

Accessor. Returns a Workbook object that represents the workbook where the current macro code is running. Read-only.

Remarks

Use this property to refer to the workbook containing your macro code. ThisWorkbook is the only way to refer to an add-in workbook from inside the add-in itself. The ActiveWorkbook property does not return the add-in workbook (it returns the workbook calling the add-in), and the Workbooks method may fail because the workbook name probably changed when you created the add-in. ThisWorkbook always returns the workbook where the code is running.

For example, use the following code to activate a dialog sheet stored in your add-in workbook.


ThisWorkbook.DialogSheets(1).Show

This property can be used only from inside Microsoft Excel. You cannot use this property to access a workbook from another application.

Example

This example closes the workbook that contains the example code. Changes to the workbook, if any, are not saved.


ThisWorkbook.Close savechanges:=False