Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Stop the workbook from closing in Auto_Close

I need the the auto_close procedure to check stuff before the workbook closes
then give the user the option to not close based on the results. I'm sure
it'll be something simple but I just don't know what it is. The code so far
is as follows...

Sub auto_close()

If Range("H4").Value < "ALL JOBS COMPLETE" Then
msg1 = MsgBox("One or more jobs are still outstanding." & Chr(10) & _
"Are you sure you want to exit?", vbYesNo, "Jobs Outstanding")
If msg1 = vbNo Then
[insert "no close" code here]
Else
GoTo 10
End If
End If

10 End Sub
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default Stop the workbook from closing in Auto_Close

I find it easier to use the _BeforeClose event of ThisWorkbook. e.g.
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Worksheets("WhichSheet").Range("H4").Value < "ALL JOBS COMPLETE" Then
msg1 = MsgBox("One or more jobs are still outstanding." & vbNewLine & _
"Are you sure you want to exit?", vbYesNo, "Jobs Outstanding")
If msg1 = vbNo Then
Cancel = True
End If
End If
End Sub

You should specify which sheet the range "H4" refers to, otherwise it is the
active sheet, which may or may not correct.

NickHK

"gp133" wrote in message
...
I need the the auto_close procedure to check stuff before the workbook

closes
then give the user the option to not close based on the results. I'm sure
it'll be something simple but I just don't know what it is. The code so

far
is as follows...

Sub auto_close()

If Range("H4").Value < "ALL JOBS COMPLETE" Then
msg1 = MsgBox("One or more jobs are still outstanding." & Chr(10)

& _
"Are you sure you want to exit?", vbYesNo, "Jobs Outstanding")
If msg1 = vbNo Then
[insert "no close" code here]
Else
GoTo 10
End If
End If

10 End Sub



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3
Default Stop the workbook from closing in Auto_Close

Thanks a lot for your help. I knew it would be simple!

"NickHK" wrote:

I find it easier to use the _BeforeClose event of ThisWorkbook. e.g.
Private Sub Workbook_BeforeClose(Cancel As Boolean)
If Worksheets("WhichSheet").Range("H4").Value < "ALL JOBS COMPLETE" Then
msg1 = MsgBox("One or more jobs are still outstanding." & vbNewLine & _
"Are you sure you want to exit?", vbYesNo, "Jobs Outstanding")
If msg1 = vbNo Then
Cancel = True
End If
End If
End Sub

You should specify which sheet the range "H4" refers to, otherwise it is the
active sheet, which may or may not correct.

NickHK

"gp133" wrote in message
...
I need the the auto_close procedure to check stuff before the workbook

closes
then give the user the option to not close based on the results. I'm sure
it'll be something simple but I just don't know what it is. The code so

far
is as follows...

Sub auto_close()

If Range("H4").Value < "ALL JOBS COMPLETE" Then
msg1 = MsgBox("One or more jobs are still outstanding." & Chr(10)

& _
"Are you sure you want to exit?", vbYesNo, "Jobs Outstanding")
If msg1 = vbNo Then
[insert "no close" code here]
Else
GoTo 10
End If
End If

10 End Sub




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
close workbook without closing excel and stop recursive function chris Excel Discussion (Misc queries) 3 July 10th 06 08:23 PM
STOP WORKBOOK CLOSING KandK Excel Discussion (Misc queries) 2 May 5th 06 09:40 AM
Validation to stop workbook closing Jonathan Excel Discussion (Misc queries) 2 March 31st 06 11:35 AM
Stop Workbook from closing. beauty_bobaloo Excel Programming 5 February 23rd 06 12:45 PM
closing excel after closing a workbook CWalsh[_2_] Excel Programming 3 January 21st 04 03:33 PM


All times are GMT +1. The time now is 05:17 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"