Solved

IF + Message box

Posted on 2011-09-08
3
187 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Do you use a spreadsheet like Microsoft's Excel?  Have you ever wanted to link out to a non excel file on your computer or network drive?  This is the way I found to do it!
The viewer will learn how to create two correlated normally distributed random variables in Excel, use a normal distribution to simulate the return on different levels of investment in each of the two funds over a period of ten years, and, create a …
This Micro Tutorial will demonstrate how to use longer labels with horizontal bar charts instead of the vertical column chart.

635 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