Expiring Today—Celebrate National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

VBA - Check a tab exists in another sheet

Posted on 2014-07-30
4
Medium Priority
?
183 Views
Last Modified: 2014-07-30
Hi,

I want to check to see if a tab exists in a wb xyz.xls called "Combined Data"

If it does not, do nothing, carry on

if it does, message box "Error, new data not saved", then exit sub

Thanks
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
  • 2
  • 2
4 Comments
 
LVL 21

Expert Comment

by:Randy Poole
ID: 40229202
so this will be a different workbook then the active one?
0
 

Author Comment

by:Seamus2626
ID: 40229205
Yes, thanks
0
 
LVL 21

Accepted Solution

by:
Randy Poole earned 2000 total points
ID: 40229218
Sub CheckPageinWB()
    Dim xls As Excel.Worksheet
    Dim xlb As Excel.Workbook
    Dim hassheet As Boolean
    hassheet = False
    
    Set xlb = Workbooks.Open("xyz.xls")
    For Each xls In xlb.Worksheets
        If xls.Name = "Combined Data" Then
            hassheet = True
            Exit For
        End If
    Next
    xlb.Close False
    If (hassheet) Then MsgBox "Error, new data not saved"
End Sub

Open in new window

0
 

Author Closing Comment

by:Seamus2626
ID: 40229229
Thanks Randy
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

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,…
This tutorial explains how to create a series of drop-down lists that are dependent upon prior selections to guide (“force”) the user to make the correct selection and reduce data errors within Microsoft Excel. Excel 2010 was used for this tutorial;…
This Micro Tutorial will demonstrate how to create pivot charts out of a data set. I also added a drop-down menu which allows to choose from different categories in the data set and the chart will automatically update.
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

719 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