vbNO response to MsGBox not working

Jimmy P

New Member
Joined
Aug 23, 2014
Messages
45
I have a sub with a MsgBox that asks for a Yes/No response. When No is selected the Shell command still executes. Suggestions?t

Sub ViewSavedFile()

MsgBox "To view your saved file Click Yes and select the one with your name and the latest Date/Time." _
& vbCr & vbCr & "Otherwise Click No" _
, vbYesNo + vbQuestion, "View Saved File"

If vbYes Then
Shell "Explorer.exe /root,C:\Users\Jim 2\Desktop\Sample Results", vbNormalFocus

Else

If vbNo Then
Exit Sub

End If
End If

End Sub
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
7,324
Office Version
  1. 2019
Platform
  1. Windows
see if this change to your code helps:

Code:
Sub ViewSavedFile()
    Dim msg As Integer


    msg = MsgBox("To view your saved file Click Yes and select the one with your name and the latest Date/Time." _
               & vbCr & vbCr & "Otherwise Click No" _
        , vbYesNo + vbQuestion, "View Saved File")


    If msg = vbNo Then Exit Sub
    
    Shell "Explorer.exe /root,C:\Users\Jim 2\Desktop\Sample Results", vbNormalFocus


End Sub

Dave
 

Jimmy P

New Member
Joined
Aug 23, 2014
Messages
45
dmt32,

Got it. Had to put the shell command in a new sub and call it from the ViewSavedResults sub. Don't know why the other way didn't work?
______________________________________________
Dim msg As Integer

msg = MsgBox("To view your saved file Click Yes and select the one with your name and the latest Date/Time." _
& vbCr & vbCr & "Otherwise Click No" _
, vbYesNo + vbQuestion, "View Saved File")
If msg = vbYes Then
Call OpenUserFolder
If msg = vbYNo Then Exit Sub
Else

End If

End Sub
_______________________________________________________
Sub OpenUserFolder()

Shell "Explorer.exe /root,C:\Users\Jim 2\Desktop\Sample Results", vbMaximizedFocusl

End SUb
 
Master Excel Bundle

Excel contains over 450 functions, with more added every year. That’s a huge number, so where should you start? Right here with this bundle.

Forum statistics

Threads
1,164,016
Messages
5,834,941
Members
430,327
Latest member
Mr_Himalayan778

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
Top