Solved

IF + Message box

Posted on 2011-09-08
3
184 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

ScreenConnect 6.0 Free Trial

Explore all the enhancements in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

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,…
When you see single cell contains number and text, and you have to get any date out of it seems like cracking our heads.
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 Microsoft Excel how to add style and sexy appeal to horizontal bar charts.

803 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