PC Review


Reply
Thread Tools Rate Thread

Cannot Dismiss the MsgBox

 
 
Ron
Guest
Posts: n/a
 
      3rd Jul 2009
Hello all, I don't have a clue why when I click on the OK or Cancel
button the MsgBox does not go away. The only way I can get out is to
kill Excel with Control/Alt Delete and end Excel. How do I program
the cancel button to end the sub or at least dismiss the MsgBox when
clicking OK or Cancel? Any suggestions? Thank you all for your
assistance, Ron


Sub testfollowup()
Dim c As Range
For Each c In ActiveSheet.Range("K12:AI10000")
If c.Font.ColorIndex = 3 Then
MsgBox "Please make additional corrections", vbExclamation +
vbOKCancel, "TEST"
Else
MsgBox "Data validated, good job!" & vbNewLine & "If the sheet is
to be printed, clicking on the Print Setup button prepares the file
for printing.", vbExclamation + vbOKCancel, "TEST"
End If
Next c
End Sub
 
Reply With Quote
 
 
 
 
OssieMac
Guest
Posts: n/a
 
      3rd Jul 2009

Hi Ron,

You need to assign the response to a variable and then test the variable for
the user's response. You can use If/Then/Else or Select Case for the testing.

Sub testfollowup()
Dim c As Range
Dim userResponse As Variant
For Each c In ActiveSheet.Range("K12:AI10000")
If c.Font.ColorIndex = 3 Then
userResponse = MsgBox("Please make additional corrections", _
vbExclamation + vbOKCancel, "TEST")
Select Case userResponse
Case vbCancel
Exit Sub 'Or other required code
Case vbOK
'Required code here
End Select
Else
userResponse = MsgBox("Data validated, good job!" _
& vbNewLine & _
"If the sheet is to be printed, " & _
"clicking on the Print Setup button " & _
"prepares the file for printing.", _
vbExclamation + vbOKCancel, "TEST")
Select Case userResponse
Case vbCancel
Exit Sub 'Or other required code
Case vbOK
'Required code here
End Select
End If
Next c
End Sub


--
Regards,

OssieMac


 
Reply With Quote
 
FSt1
Guest
Posts: n/a
 
      3rd Jul 2009

hi
you're caught in a loop. the solution i posted earlier displayed the msgbox
only when a red font was found. i added code to your other post to correct
multiple instances of red fonts ie exit sub after the msgbox. my bad for not
seeing that.
the second msgbox you added will display for each and every cell in the loop
that is not red font. this is why you can't get rid of it.
suggestion. during development and testing, choose a much smaller range. and
use step mode to trouble shoot.

what is the purpose of the second msgbox???
what are we trying to do????
if you're just adding a "good job" message at the end then move the second
msgbox OUTSIDE the loop.

post back with more info if i am not understanding.

regards
FSt1

"Ron" wrote:

> Hello all, I don't have a clue why when I click on the OK or Cancel
> button the MsgBox does not go away. The only way I can get out is to
> kill Excel with Control/Alt Delete and end Excel. How do I program
> the cancel button to end the sub or at least dismiss the MsgBox when
> clicking OK or Cancel? Any suggestions? Thank you all for your
> assistance, Ron
>
>
> Sub testfollowup()
> Dim c As Range
> For Each c In ActiveSheet.Range("K12:AI10000")
> If c.Font.ColorIndex = 3 Then
> MsgBox "Please make additional corrections", vbExclamation +
> vbOKCancel, "TEST"
> Else
> MsgBox "Data validated, good job!" & vbNewLine & "If the sheet is
> to be printed, clicking on the Print Setup button prepares the file
> for printing.", vbExclamation + vbOKCancel, "TEST"
> End If
> Next c
> End Sub
>

 
Reply With Quote
 
OssieMac
Guest
Posts: n/a
 
      3rd Jul 2009

Good pickup Rob. I was guilty of not assessing what the the rest of the code
was doing. Only providing the answer on how to handle the user response.

The following code displays the cell Id with the error and gives the user
the option of continuing the test (and perhaps make a note of the error cell
Id) or abort the test and fix the error and then run the test again. If
processing is continued then bolError is set to true so that the final msgbox
displays that there are still errors.

The final msgbox/s do not require testing the user response.

Sub testfollowup()
Dim c As Range
Dim bolErrors As Boolean
Dim userResponse As Variant
For Each c In ActiveSheet.Range("K12:AI10000")
If c.Font.ColorIndex = 3 Then
userResponse = MsgBox("Cell " & c.Address(0, 0) _
& " not corrected." & vbCrLf & _
"OK to continue or Cancel to abort test.", _
vbExclamation + vbOKCancel, "TEST")
bolErrors = True
If userResponse = vbCancel Then
Exit Sub
End If
End If
Next c

If bolErrors = False Then
MsgBox "Data validated, good job!" _
& vbNewLine & _
"If the sheet is to be printed, " & _
"clicking on the Print Setup button " & _
"prepares the file for printing.", _
vbExclamation, "TEST"
Else
MsgBox "Errors exist." & vbCrLf & _
"Correct and run test again."
End If

End Sub


--
Regards,

OssieMac


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Substituting my own MsgBox for the standard delete confirm MsgBox John S. Ford, MD Microsoft Access Getting Started 8 20th Aug 2004 12:05 AM
Substituting my own MsgBox for the standard delete confirm MsgBox John S. Ford, MD Microsoft Access Forms 8 20th Aug 2004 12:05 AM
Substituting my own MsgBox for the standard delete confirm MsgBox John S. Ford, MD Microsoft Access Form Coding 8 20th Aug 2004 12:05 AM
Re: Disabling Dismiss or Dismiss all in task reminder Sue Mosher [MVP-Outlook] Microsoft Outlook Form Programming 0 4th Aug 2004 01:58 PM
Dismiss doesn't dismiss Jeff Poretsky Microsoft Outlook 1 16th Oct 2003 05:20 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:25 AM.