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

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
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,214,767
Messages
6,121,423
Members
449,032
Latest member
egspen2

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