Message box appearing twice when closing workbook

CaptainGravyBum

Board Regular
Joined
Dec 1, 2023
Messages
77
Office Version
  1. 365
Platform
  1. Windows
Hello,
I know this is going to be a real simple fix, but the answer is eluding me so would appreciate some help.
My excel workbook has some VBA script applied in the Workbook_BeforeClose section and when it runs, there is a message box that I need to display, but it appears twice.
I'm pretty sure it's because the message box appears on the initial close workbook is triggered and then again when the script closes the workbook to save changes, I'm hoping there is a way round this.

Code is as follows:

Private Sub Workbook_BeforeClose(Cancel As Boolean)

Sheets("Cross-Charge Request").Select
Range("E4,E5,E6,B8:F10").Select
Selection.ClearContents
Range("E4").Select
MsgBox "Cross Charge Request Form Updated"
Application.DisplayAlerts = False
ThisWorkbook.Close savechanges:=True
Application.DisplayAlerts = True

End Sub
 

Excel Facts

How can you turn a range sideways?
Copy the range. Select a blank cell. Right-click, Paste Special, then choose Transpose.
Try replacing this line:
VBA Code:
ThisWorkbook.Close savechanges:=True

with this:
VBA Code:
If Saved = False Then
    ActiveWorkbook.Save
End If

I think the above will address the actual issue and alternative would be to suppress the 2nd call.
VBA Code:
Application.EnableEvents = False
ThisWorkbook.Close savechanges:=True
Application.EnableEvents = True
 
Upvote 1
Solution

Forum statistics

Threads
1,223,898
Messages
6,175,272
Members
452,628
Latest member
dd2

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