Reverse the close command

Jook

New Member
Joined
Mar 19, 2002
Messages
22
Any idea how to stop a file from closing when a before close event has been met. here is what I have so far:

Private Sub Workbook_BeforeClose(Cancel As Boolean)

If ActiveSheet.Cells(85, 12).Value > 0 And ActiveSheet.Cells(85, 9).Value < 1 Then

MsgBox "Enter a Travel Order Number"
Else: Close
End If

End Sub

After the MsgBox has been clicked I want the file not to close and return to the worksheet.

Any help would be apreciated.

Dale
 

Excel Facts

Format cells as currency
Select range and press Ctrl+Shift+4 to format cells as currency. (Shift 4 is the $ sign).
Any idea how to stop a file from closing when a before close event has been met. here is what I have so far:

Private Sub Workbook_BeforeClose(Cancel As Boolean)

If ActiveSheet.Cells(85, 12).Value > 0 And ActiveSheet.Cells(85, 9).Value < 1 Then

MsgBox "Enter a Travel Order Number"
cancel = true '<<<<#########################
Else: Close
End If

End Sub

After the MsgBox has been clicked I want the file not to close and return to the worksheet.

Any help would be apreciated.

Dale
 
Upvote 0
Hi Dale

The Cancel argument should do it.


Private Sub Workbook_BeforeClose(Cancel As Boolean)

If ActiveSheet.Cells(85, 12).Value > 0 And ActiveSheet.Cells(85, 9).Value < 1 Then

MsgBox "Enter a Travel Order Number"
Cancel = True
End If

End Sub
 
Upvote 0

Forum statistics

Threads
1,213,529
Messages
6,114,155
Members
448,554
Latest member
Gleisner2

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top