msgbox question

W

Wu

In my marco, I want to show a message box to ask " do you have open the
1244.xls file" and to show two button " yes" and "no" for user select.

If user select "yes", my marco will go on,

select "no", it will quit the marco
 
M

Mike H

Hi,

You only need to check the No button

response = MsgBox("Have you opened 1244.xls?", vbYesNo, "Your Title")
If response = vbNo Then Exit Sub

Mike
 
M

Mike H

Hi,

You may want to consider another method that doesn't rely on the user who
could prees the wrong button. This checks if the workbook is open and exits
the sub if it isn't.

Sub marine()
fname = "1244.xls"
On Error Resume Next
Workbooks(fname).Activate
If Err <> 0 Then
MsgBox "You must have workbook " & fname & " open to continue.
Exiting"
Exit Sub 'Workbook isn't open
End If
Err.Clear 'Clear errors
End Sub

Mike
 
Top