ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Worksheet Functions (https://www.excelbanter.com/excel-worksheet-functions/)
-   -   Run macro on exit worksheet/workbook (https://www.excelbanter.com/excel-worksheet-functions/38376-run-macro-exit-worksheet-workbook.html)

toontje

Run macro on exit worksheet/workbook
 
I am looking for a macro that opens a msgbox when exit the workbook to
remind you
like "you fill in your working hours?"

is that Private Sub AutoClose() ?

and where do i put it?

Ron de Bruin

Hi

Better use the beforeclose event so the user can cancel the close

Copy this in the thisworkbook module

Private Sub Workbook_BeforeClose(Cancel As Boolean)
Dim ans As Long
ans = MsgBox("Do you fill in your working hours?", vbOKCancel)
If ans = vbOK Then
'do nothing
ElseIf ans = vbCancel Then
Cancel = True
End If
End Sub


--
Regards Ron de Bruin
http://www.rondebruin.nl


"toontje" wrote in message l...
I am looking for a macro that opens a msgbox when exit the workbook to remind you
like "you fill in your working hours?"

is that Private Sub AutoClose() ?

and where do i put it?




Bob Phillips

You need Workbook_BeforeClose, as you can Cancel the close

Private Sub Workbook_BeforeClose(Cancel As Boolean)
If your condition not met Then
Cancel=True
End If
End Sub

'This is workbook event code.
'To input this code, right click on the Excel icon on the worksheet
'(or next to the File menu if you maximise your workbooks),
'select View Code from the menu, and paste the code

--

HTH

RP
(remove nothere from the email address if mailing direct)


"toontje" wrote in message
l...
I am looking for a macro that opens a msgbox when exit the workbook to
remind you
like "you fill in your working hours?"

is that Private Sub AutoClose() ?

and where do i put it?




Bill Kuunders

You will need to put it in the workbook code.

Right click on the small picture to the left of the menu item "File"
select "workbook" in the dropdown next to "general"
select "before close" or if you like "before save" in the dropdown next to
"open"
and enter
Msgbox "Heb je je uren ingevuld????"
between the lines already there.

Have fun.

--
Groeten vanuit Nieuw Zeeland
Willy Kuunders

"toontje" wrote in message
l...
I am looking for a macro that opens a msgbox when exit the workbook to
remind you
like "you fill in your working hours?"

is that Private Sub AutoClose() ?

and where do i put it?





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

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com