Solved

IF + Message box

Posted on 2011-09-08
3
182 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 400 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 100 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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

A little background as to how I came to I design this code: Around 5 years ago I designed an add-in that formatted Excel files to a corporate standard, applying different cell colours and font type depending on whether the cells contained inputs,…
INDEX and MATCH can be used to great effect to replace HLOOKUP and VLOOKUP as it does not have the limitation of needing the data to be sorted so that the reference value is in the first column or row. It also has the ability to perform a bi-directi…
This Micro Tutorial demonstrate the bugs in Microsoft Excel for Mac with Pivot Charts.
This Micro Tutorial will demonstrate how to use a scrolling table in Microsoft Excel using the INDEX function.

705 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now