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
 

Some videos you may like

Excel Facts

Copy a format multiple times
Select a formatted range. Double-click the Format Painter (left side of Home tab). You can paste formatting multiple times. Esc to stop

dmt32

Well-known Member
Joined
Jul 3, 2012
Messages
6,086
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
 

Watch MrExcel Video

Forum statistics

Threads
1,108,960
Messages
5,525,906
Members
409,671
Latest member
nasseralateek

This Week's Hot Topics

Top