Solved

VBA - Check a tab exists in another sheet

Posted on 2014-07-30
4
170 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
  • 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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

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…
How to quickly and accurately populate Word documents with Excel data, charts and images (including Automated Bookmark generation) David Miller (dlmille) Synopsis In this article you’ll learn how to use ExcelToWord! to copy data,charts, shapes …
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
This Micro Tutorial will demonstrate on a Mac how to change the sort order for chart legend values and decrpyt the intimidating chart menu.

895 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

15 Experts available now in Live!

Get 1:1 Help Now