Running a macro Upon Closing

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I have figured out the code to run Excel in Full Screen mode and get it to
have a "non excel" look to it. I want to run the reverse code however upon
closing excel. What code should I use to get a macro to run as I close the
program down.
Private Sub Workbook_Close() ???
Private Sub Auto_Close() ???

Or somethine entirely different. Thanks!
Chris
 
Auto Close is a little older that workbook close but they both function
exactly the same. The advantage to auto close is that you can place it in a
modue and export it for later use. But either way is just fine...

HTH
 
Hi Chris

Adding: You should imo use the parallell to what you use on opening, for the
sake of symmetry and consistence.

But test what happens if you're prompted "save changes ?" and you select
Cancel. The file stays open but the macro has already done its job. So you
must have your code deal with this before it does its real job.

HTH. Best wishes Harald
 
I guess my basic problem is that I can't figure out how to get a macro to
automatically run as I close down excel. I figured out how to have some code
run at the opening, and I want all of it to be reversed as I shut it
down...So, I want all the changes I made to be undone as I close the
program. Im just now sure what kind of code, or where to put the code in the
first place. For some reason, the way excel is set up at my work, If I was
just to run the code that puts it into full screen mode, and gets rid of all
menus...even if I close excel it and don't save any changes, the code seems
to be applie to any other excel worksheet I open. This is the reson I want
to reverse the code everytime this particular excel sheet closes down.
Thanks for the replies so far!
Chris
 
Try the following of some thing like it

In ThisWorkbook module:

Private Sub Workbook_Open()
Application.DisplayFullScreen=True

' Other formatting code
End sub


Private Sub Workbook_BeforeClose(Cancel As Boolean)
Application.DisplayFullScreen=False
'Code to reverse other formatting
End Sub
 
Hi Chris

Apolgogies for this: It's like "I know how to make a left turn with my car,
but I can't figure our how to make a right turn" -no harm intended.

Here's some useful theory:
http://www.cpearson.com/excel/events.htm
note that there's a big difference between opening/closing Excel and
opening/closing your spesific file. For Excel herself see
http://www.cpearson.com/excel/AppEvent.htm

Sounds like you're making a "dictator app" for Excel. Consider carefully
what will happen if the user wants to work with several Excel files
simoultaneously, that is very common. Maybe your changes should happen when
you activate/deactivate your file, not on open/close.

HTH. Best wishes Harald

"Still confused Excel Fan..." <Still confused Excel
(e-mail address removed)> skrev i melding
news:[email protected]...
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top