Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.misc
Nigel
 
Posts: n/a
Default run macro on workbook close

Hi,

Can you run a macro when you close a workbook or do you have do this through
a button? i konw you can run a macro on workbook open but i need it the other
way round.
if you can't, can you prevent the workbook being closed via the red crox in
the corner to force use of the button?

thanks in advance,



Nigel

  #3   Report Post  
Posted to microsoft.public.excel.misc
Gord Dibben
 
Posts: n/a
Default run macro on workbook close

Nigel

In the Thisworkbook Module

Private Sub Workbook_BeforeClose(Cancel As Boolean)

'your code here

End Sub


Gord Dibben Excel MVP

On Tue, 29 Nov 2005 08:50:16 -0800, "Nigel"
wrote:

Hi,

Can you run a macro when you close a workbook or do you have do this through
a button? i konw you can run a macro on workbook open but i need it the other
way round.
if you can't, can you prevent the workbook being closed via the red crox in
the corner to force use of the button?

thanks in advance,



Nigel


  #4   Report Post  
Posted to microsoft.public.excel.misc
TJLV
 
Posts: n/a
Default run macro on workbook close


In addition to before close you can use
Auto open. for example when I open the file containing the following macro
all the sheets are hidden except one that makes the usert select a box that
he agrees to the conditions given on the visible page. The accept button
runs a macro that unhides the pages. Since this is done automatically at
opening it effectively does the same thing as hiding the pages before closing.

Sub Auto_open()
'
' Auto_open Macro
' Macro recorded 5/23/2005 by TJLV
'

'
' Sheets("instructions").Select


Sheets("opening").Visible = True
Sheets("instructions").Visible = False
Sheets("reports").Visible = False
Sheets("input").Visible = False
Sheets("Optimize").Visible = False
Sheets("combine").Visible = False
Sheets("calc").Visible = False
Sheets("split").Visible = False
Sheets("Site1").Visible = False
Sheets("Site2").Visible = False
Sheets("Siteagg").Visible = False
Sheets("rates").Visible = False

End Sub


--
TJLV


"Nigel" wrote:

Hi,

Can you run a macro when you close a workbook or do you have do this through
a button? i konw you can run a macro on workbook open but i need it the other
way round.
if you can't, can you prevent the workbook being closed via the red crox in
the corner to force use of the button?

thanks in advance,



Nigel

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
Protect Workbook vs Worksheet?? Dan B Excel Worksheet Functions 3 November 7th 05 09:02 PM
Macro Help In Excel welshlad Excel Discussion (Misc queries) 14 October 26th 05 02:34 PM
Applying same macro to all worksheets in workbook [email protected] Excel Discussion (Misc queries) 2 October 19th 05 11:25 PM
close only one workbook bobsmom70601 New Users to Excel 1 March 8th 05 09:43 PM
Copying a workbook with custom toolbar assigned to a macro Matt W Excel Discussion (Misc queries) 1 February 4th 05 10:46 PM


All times are GMT +1. The time now is 04:30 AM.

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

About Us

"It's about Microsoft Excel"