Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MACROS

Status
Not open for further replies.

DSerr77

Technical User
Jul 21, 2004
42
US
Does anyone know how to activate a macro with a file command (i.e. run a macro upon closing a workbook)?
 


Hi,

Take a look at Excel Events in VB Help.

Double click the ThisWorkbook Object.

Select Workbook in the Code window Objects DropDown

Select the Close event in the Code Window Procedures DropDown and run your macro in here.

Skip,

[glasses] [red]Be Advised![/red] The only distinction between a bird with one wing and a bird with two, is merely...
a difference of A Pinion! [tongue]
 
Hi DSerr77,

You can run a macro upon closing a workbook via a 'BeforeClose' sub in the 'ThisWorkbook' module. For example:
Code:
Private Sub Workbook_BeforeClose(Cancel As Boolean)
Msgbox "Goodbye"
End Sub
There's a bunch of other workbook-level event driven subs availavle there too, which you can see if you double-click on the 'ThisWorkbok' module, then on the drop-down box at the top-right. Likewise for individual worksheets.

Cheers

[MS MVP - Word]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top