Microsoft Office Tutorials and References
In Depth Information
ThisWorkbook returns a Wo rkbook object that refers to the workbook that contains the macro
that’s currently running. This property lets Add-Ins refer to the workbook that contains the
code. ActiveWorkbook will not work because it refers to the currently active workbook and
not the workbook that actually contains the code being executed.
The following example demonstrates the ThisWorkbook property by displaying a message
box with the name of the active workbook and the name of the workbook the macro is being
Dim strMessage As String
strMessage = "Active Workbook = " & ActiveWorkbook.Name & vbCrLf
strMessage = strMessage & "This Workbook = " & ThisWorkbook.Name
MsgBox strMessage, vbOKOnly + vbInformation, _
"Microsoft Office Excel 2003 Programming Inside Out"
Methods are the actions that objects can perform. They allow the contents of the object
container to be processed. You can think of it as a kitchen blender. The blender is the object
container. The food placed inside the blender is the contents. Each of the individual buttons,
stir, chop, liquefy, and so on, is a different method.
Calculate forces all open workbooks to recalculate all cells that contain new, changed, or
volatile cells and their dependents. Using this method is similar to pressing the F9 key, and it
is used to force Excel to recalculate a workbook when the Calculation option in the Tools,
Options dialog box has been set to manual. This example recalculates all open workbooks if
the Calculation option is not set to automatic.
If Application.Calculation <> xlCalculationAutomatic Then