DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

+ Reply to Thread
Results 1 to 2 of 2
  1. #1
    Join Date
    Aug 2007
    Posts
    58

    Question Determine if Worksheet Exists

    I have the following Code:

    Code:
    With ActiveSheet
            LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
        Worksheets(2).Select
        Range("A1:F85").Select
        Selection.Copy
        Sheets(1).Select
        Range("A" & LastRow).Select
        ActiveSheet.Paste
        Range("A1").Select
        End With
        
        With ActiveSheet
            LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
        Worksheets(3).Select
        Range("A1:F85").Select
        Selection.Copy
        Sheets(1).Select
        Range("A" & LastRow).Select
        ActiveSheet.Paste
        Range("A1").Select
        End With
        
        With ActiveSheet
            LastRow = .Cells(.Rows.Count, "A").End(xlUp).Row + 1
        Worksheets(4).Select
        Range("A1:F85").Select
        Selection.Copy
        Sheets(1).Select
        Range("A" & LastRow).Select
        ActiveSheet.Paste
        Range("A1").Select
        End With
    I need a way to tell the macro to run only if the worksheet exist. For example, if Worksheet(4) does not exist, then I do not want that portion of the code above to run.

  2. #2
    Join Date
    Aug 2005
    Location
    Hermosillo, Sonora, Mexico
    Posts
    103
    'Declarations
    Dim xls As Excel.Application
    Dim xlswbook As Excel.Workbook

    'Instantiate
    Set xls = New Excel.Application
    Set xlswbook = xls.Workbooks.Open("SomeXlsFile")

    'Navigate thru all sheets
    For I = 1 To xlswbook.Sheets.Count
    MsgBox xlswbook.Sheets(I).Name
    Next I

Similar Threads

  1. Check if file exists
    By John Knoop in forum .NET
    Replies: 8
    Last Post: 02-28-2010, 01:57 PM
  2. Bug with Creation of Objects in SQL *Plus Worksheet
    By Michael Cole in forum Database
    Replies: 2
    Last Post: 04-02-2003, 03:06 PM
  3. A question about EXISTS
    By Richard Hart in forum Database
    Replies: 6
    Last Post: 01-09-2002, 01:50 PM
  4. How to determine if "string" exists in Database?
    By Bassel Tabbah in forum VB Classic
    Replies: 2
    Last Post: 09-13-2001, 05:55 AM
  5. determining if a table exists
    By Jon in forum Database
    Replies: 2
    Last Post: 05-11-2000, 07:38 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


Top DevX Stories

Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL


Sponsored Links