Solved

IF + Message box

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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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

Suggested Solutions

Title # Comments Views Activity
Excel VBA inserting a formula 12 39
Error 1004 Excel 2013 11 18
Sort columns by the column header Excel 2016 VBA 5 14
NEED TO COUNT THE PAIR 12 14
Improved? Move/Copy Add-in Replacement - How to avoid the annoying, “A formula or sheet you want to move or copy contains the name XXX, which already exists on the destination worksheet.” David Miller (dlmille)  It was one of those days… I wa…
Freeze panes is an option within all variants of Excel to enable parts of a sheet to remain stationary when the cursor is in another part of the sheet. This is a very useful feature which is overlooked or under used.
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 demonstrates in Microsoft Excel how to consolidate your marketing data by creating an interactive charts using form controls. This creates cool drop-downs for viewers of your chart to choose from.

752 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