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

Which lookup functions find a value equal or greater than the lookup value?
MATCH uses -1 to find larger value (lookup table must be sorted ZA). XLOOKUP uses 1 to find values greater and does not need to be sorted.
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
 
Upvote 0
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
 
Upvote 0

Forum statistics

Threads
1,215,025
Messages
6,122,734
Members
449,094
Latest member
dsharae57

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