Unexpected MsgBox...

Rob52

New Member
Joined
Feb 13, 2012
Messages
3
Hi,

This is an interesting one...

I am just completing a fairly extensive project written in Excel for VBA and I have come across an anomaly that seems to make no sense at all.

To start with I'm using Excell 2002 (Yes I know but it's what the firm has got and I have to live with it:().

The problem is that the project ends with a series of instructions that saves the current workbook before exiting (Nothing unusual there). The code is as follows...

Code:
Sub SaveAndExit()

    Application.CutCopyMode = False
    ActiveWorkbook.Save
    
    
    Application.Quit

End Sub

At another point in the project, an error checking routine displays a standard MsgBox as an error message as follows...

Code:
Err2:

Vect = MsgBox("No xxxx. Do you wish to add a xxxx? (Y/N)", vbYesNo, "xxxx Prompt")

The problem is that sometimes, when the save routine runs, the file is saved, then, beyond all reason, the msgBox is displayed. Once the msgbox is cleared by the operator, the 'Application.Quit' instruction runs.

The thing is that at no time, during the running of the project, has the MsgBox been invoked and a 'Stop' instruction inserted before the line that invokes the msgBox makes no difference.

Also inserting a 'Stop' instruction prior to the 'Application.Quit' instruction breaks the routine as expected but the MsgBox isn't displayed even when the routine is resumed.

None of this makes any sense to me... does it ring any bells with anyone else...

Rob
 

Excel Facts

Using Function Arguments with nested formulas
If writing INDEX in Func. Arguments, type MATCH(. Use the mouse to click inside MATCH in the formula bar. Dialog switches to MATCH.
You can see what the error is by putting in another message box whilst testing if that's any help?

Code:
MsgBox Err.Number & " " & Err.Description
 
Upvote 0
Thanks for the reply. Sadly that didn't help. The error number shows as 0.

I have, however, resolved the problem (although I've no idea why...:confused:).

When I was playing with the message box, I discovered that placing it after the 'quit' line displays the message box even though the parser should never reach that point. Putting a 'stop' instruction after the 'quit', beyond all logic, forces the routine to close without problem.

Regards

Robin
 
Upvote 0

Forum statistics

Threads
1,203,213
Messages
6,054,200
Members
444,708
Latest member
David R__

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