LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 87
Default How to enter a macro that performs when a file is closed

This I did not know. Thanks for this information I will use it in future to
try and answer my questions first.

"Rick Rothstein (MVP - VB)" wrote:

Event procedures are a special kind of subroutine... the argument list for
it has a required structure and you can't change it; however, you don't have
to remember what the individual argument lists for the various events are.
When you go to the code window for a worksheet or, as in this case, the
workbook, the drop down to the left in the title bar area of the code window
allows you to select the Worksheet or Workbook (as the case may be). For the
workbook code window, selecting Workbook from that list populates the drop
down on the right side of the title bar area with all of its available
events. In that drop down, you will see the BeforeClose event and if you
select it, it will create the event subroutine header for you. That header
is...

Private Sub Workbook_BeforeClose(Cancel As Boolean)

The Cancel argument (a Boolean, hence it is either True or False) is a
method the event gives you to communicate with the code that triggered the
event. If, inside the BeforeClose event, you set Cancel equal to True, it
tells Excel to not Close. This means that you can create code to exam
certain situations you deem important (for example, having a certain cell
filled in or not) and cancel the close operation the user initiated if those
situations warrant it. Of course, good programming practice would be to
include code that pops a message box up and tells the user his/her close
request is being denied and why.

Rick


"Leanne" wrote in message
...
Hi Mike,

Thank you! I knew the 'sheet visible' bit but did not know the before
close
event.

Out of interest - what does this do/mean (Cancel As Boolean)


"Mike H" wrote:

Use the before_close event
Alt+Fll to open VB editor. double click 'This workbook' and paste this in

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Sheets("Sheet1").Visible = False
End Sub

Mike

"Leanne" wrote:

I want a sheet to be hiden when the file is closed.

I have done the code to unhide it should the user require but because
of
this I want it hiden again when the file is closed (if it has been
unhiden)

Can any one tell me where/how I write this?





 
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
Macro Looks for Cell Contents & Performs Action watchtower Excel Programming 1 August 10th 07 02:36 PM
Calling a macro from a closed file Peter[_61_] Excel Programming 5 May 10th 07 05:42 PM
Run macro when file is opened and closed mcphc Excel Programming 2 February 20th 07 11:32 AM
How to create a macro which performs a copy-and-paste task every 5mins after data is refreshed from web page? ­»´ä®a©~¸Ë­× Excel Worksheet Functions 0 December 5th 06 08:57 AM
How to change macro so it performs actions on ACTIVE sheet? Tom9283 Excel Discussion (Misc queries) 6 April 15th 05 07:32 AM


All times are GMT +1. The time now is 09:52 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"