Close MessageBox on closing Excel file

Ciupaz

New Member
Joined
Mar 9, 2023
Messages
10
Office Version
  1. 2019
Platform
  1. Windows
Hello,
I'm getting a messagebox on running excel macros.
I need to close that messagebox using VBscript in-order to close the Excel .
Is it possible?

Thanks a lot in advance.

Luis
 

Excel Facts

Did you know Excel offers Filter by Selection?
Add the AutoFilter icon to the Quick Access Toolbar. Select a cell containing Apple, click AutoFilter, and you will get all rows with Apple
Not sure how "WScript.Echo" got activated
 
Upvote 0
Not used to this form. maybe the following will work


VBA Code:
Sub endTheScript()
    Dim AckTime As Integer, InfoBox As Object
    Set InfoBox = CreateObject("WScript.Shell")
    objExcel.ActiveWorkbook.Save
    objExcel.ActiveWorkbook.Close (0)
    objExcel.Quit
    AckTime = 5
    Select Case InfoBox.Popup("Click OK (Message closes automatically after " & AckTime & " seconds).", _
    AckTime, "This is your Message Box", 0)
        Case 1, -1
            Exit Sub
    End Select
    WScript.Quit
End Sub
 
Upvote 0
Not used to this form. maybe the following will work


VBA Code:
Sub endTheScript()
    Dim AckTime As Integer, InfoBox As Object
    Set InfoBox = CreateObject("WScript.Shell")
    objExcel.ActiveWorkbook.Save
    objExcel.ActiveWorkbook.Close (0)
    objExcel.Quit
    AckTime = 5
    Select Case InfoBox.Popup("Click OK (Message closes automatically after " & AckTime & " seconds).", _
    AckTime, "This is your Message Box", 0)
        Case 1, -1
            Exit Sub
    End Select
    WScript.Quit
End Sub
I have to insert this Sub in my all code?
 
Upvote 0
It replaces the sub with that name as that is the one that is stopping the closure
 
Upvote 0
See if this is any better. As I said I do not usually us Wscipt


VBA Code:
Sub endTheScript()
    Dim AckTime As Integer
    objExcel.ActiveWorkbook.Save
    objExcel.ActiveWorkbook.Close (0)
    objExcel.Quit
    AckTime = 5
    Select Case objShell.Popup("Click OK (Message closes automatically after " & AckTime & " seconds).", _
    AckTime, "This is your Message Box", 0)
        Case 1, -1
            Exit Sub
    End Select
    WScript.Quit
End Sub
 
Upvote 0

Forum statistics

Threads
1,215,436
Messages
6,124,869
Members
449,192
Latest member
MoonDancer

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