Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default Run Macros after a certain action is taken.

I have written a macro that I use a lot and I always use it when I am closing
the document. Is there a way that I can have the macro run automticly when I
close the document?
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 5,939
Default Run Macros after a certain action is taken.

Right click the Excel icon on the menu bar at the top left and select view
code. This will take you to the VBE window in the ThisWorkbook module. There
are 2 drop downs menus just abopve the code window. One will say general and
the other declarations. Chnge the one that says general to Workbook. Now the
one that said declarations will show you all of the workbook events that you
can use. Select BeforeClose and a code stub will be added, something like this

Private Sub Workbook_BeforeClose(Cancel As Boolean)
'Call MyMacro 'Add your code here
End Sub
--
HTH...

Jim Thomlinson


"Precise Eng" wrote:

I have written a macro that I use a lot and I always use it when I am closing
the document. Is there a way that I can have the macro run automticly when I
close the document?

  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 6,953
Default Run Macros after a certain action is taken.

Use the workbooks BeforeClose event to call your macro.

See Chip Pearson's Overview page on events
http://www.cpearson.com/excel/events.htm

You would go to the VBE, in the project explorer, under your workbook, right
click on Thisworkbook and select view code. At the top of the module will be
two dropdowns. From the left dropdown, select Workbook and from the right
dropdown Select BeforeClose. (or you might want to use BeforeSave - only you
would know which is correct)

this will put in the declaration for the procedu

Private Sub Workbook_BeforeClose(Cancel As Boolean)

End Sub

You would call your macro he

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Mymacro
End Sub

--
Regards,
Tom Ogilvy

"Precise Eng" wrote:

I have written a macro that I use a lot and I always use it when I am closing
the document. Is there a way that I can have the macro run automticly when I
close the document?

Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Excell copy action pauses for 15 second for the smallest action Meekal Excel Discussion (Misc queries) 1 January 28th 10 04:30 PM
Allow no action to be taken Smitty[_2_] Excel Worksheet Functions 4 January 23rd 08 10:52 PM
On Action Greg Wilson Excel Programming 0 March 26th 06 11:51 PM
OLE action? choice[_2_] Excel Programming 1 February 27th 05 06:10 PM
an OLE Action Charles Excel Programming 0 September 14th 04 06:24 AM


All times are GMT +1. The time now is 07:56 AM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"