Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
toontje
 
Posts: n/a
Default 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?
  #2   Report Post  
Ron de Bruin
 
Posts: n/a
Default

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?



  #3   Report Post  
Bob Phillips
 
Posts: n/a
Default

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?



  #4   Report Post  
Bill Kuunders
 
Posts: n/a
Default

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?



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
Help with macro looping and color query function kevinm Excel Discussion (Misc queries) 10 May 26th 05 01:25 AM
Macro: Exit active workbook without save? Don Excel Worksheet Functions 0 May 20th 05 06:47 AM
on exit macro ditchy Excel Discussion (Misc queries) 2 May 3rd 05 12:11 AM
Playing a macro from another workbook Jim Excel Discussion (Misc queries) 1 February 23rd 05 10:12 PM
Date macro Hiking Excel Discussion (Misc queries) 9 February 3rd 05 12:40 AM


All times are GMT +1. The time now is 06:45 PM.

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"