Responding to system shutdown

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

Guest

Is there an event that fires in Excel when the shutdown.exe -f is used
outside Excel to reboot the system?

I have an Excel application running and I would like the opportunity to save
the workbook before the system shuts down.
 
Unless you have a very old version of Windows/Office/Excel it should
automatically save your work in the event of system failure. It will give
you an option on restart for which file you want to save under the original
file name. I always check the data in both versions before I decide, just to
be sure.
 
JLGWhiz said:
Unless you have a very old version of Windows/Office/Excel it should
automatically save your work in the event of system failure. It will give
you an option on restart for which file you want to save under the original
file name. I always check the data in both versions before I decide, just to
be sure.

We are using Excel to gather data from some solar systems. So its not
something that a user is working with interactive. So I was looking for an
event that will fire when shutdown.exe -f is used to reboot the system. That
way I can put code in the event to save the current set of data.
 
I think the only way would be to create a UserForm to load on startup and
then examine the CloseMode in QueryClose to see if the application is being
shut down by Windows.

Private Sub UserForm_QueryClose(Cancel As Integer, CloseMode As Integer)
' 2 = Windows is shutting down
' 3 = Task Manager is killing the process
If (CloseMode = 2) Or (CloseMode = 3) Then
' your shutdown code
End If
End Sub

Note that the UserForm need not be visible. You can just Load it without
Showing it. E.g.,

Sub Workbook_Open()
Load frmMyForm
End Sub


--
Cordially,
Chip Pearson
Microsoft MVP - Excel, 10 Years
Pearson Software Consulting
www.cpearson.com
(email on the web site)
 

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