Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

IF + Message box

Posted on 2011-09-08
3
Medium Priority
?
191 Views
Last Modified: 2012-05-12
Hi,

i need a piece of code that asks the question whether another WB is open, if the answer is Yes, i need the msgbox+then exit sub, if the answer is No, i want to carry on through the sub

I have attempted to start it below but cannot seem to make a messagebox and exit sub work!

Thanks
Seamus

If MsgBox("Have you another Workbook Open?", vbYesNo) = vbYes Then MsgBox "Close that File, you can only have this file open"
0
Comment
Question by:Seamus2626
3 Comments
 
LVL 18

Accepted Solution

by:
Cluskitt earned 1600 total points
ID: 36502383
If MsgBox("Have you another Workbook Open?", vbYesNo) = vbYes Then
MsgBox "Close that File, you can only have this file open"
Exit Sub
End If
0
 
LVL 1

Assisted Solution

by:nishantace
nishantace earned 400 total points
ID: 36502482
Can you first check whether your this code is in a SUB or Function and accordingly you will have to use EXIT SUB or Exit Function

You can try out following for SUB:

If MsgBox("Have you another Workbook Open?", vbYesNo,"Confirm Please?") = vbYes Then
MsgBox "Close that File, you can only have this file open"
Exit Sub
End If

You can try out following for Function:


If MsgBox("Have you another Workbook Open?", vbYesNo,"Confirm Please?") = vbYes Then
MsgBox "Close that File, you can only have this file open"
Exit Function
End If

Regards,

NishantAce
0
 

Author Closing Comment

by:Seamus2626
ID: 36502638
Thanks guys!
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This code takes an Excel list of URL’s and adds a header titled “URL List”. It then searches through all URL’s in column “A”, looking for duplicates. When a duplicate is found, it is moved to the top of the list. The duplicate URL’s are then highlig…
Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
The viewer will learn how to use a discrete random variable to simulate the return on an investment over a period of years, create a Monte Carlo simulation using the discrete random variable, and create a graph to represent the possible returns over…
This Micro Tutorial will demonstrate in Google Sheets how to use the HYPERLINK function to create live links inside your spreadsheet.

972 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question