Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Jun 2003
    Posts
    7
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Find Function in VBA (Excel professional)

    I need to write a macro that will look in the workbook of my specification and search to see if a specified worksheet exists.

    Help!

  2. #2
    WS Lounge VIP sdckapr's Avatar
    Join Date
    Jul 2002
    Location
    Pittsburgh, Pennsylvania, USA
    Posts
    11,225
    Thanks
    14
    Thanked 342 Times in 335 Posts

    Re: Find Function in VBA (Excel professional)

    check this out. It is from John Walkenbach's site:

    http://j-walk.com/ss/excel/tips/tip54.htm

    Steve

  3. #3
    Uranium Lounger
    Join Date
    Jan 2001
    Location
    South Carolina, USA
    Posts
    7,295
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Find Function in VBA (Excel professional)

    Something like this:

    <pre>Public Sub DoesSheetExist()
    Dim vFName As Variant, oSheet As Worksheet, oWB As Workbook
    vFName = Application.GetOpenFilename()
    If vFName = False Then Exit Sub
    Set oWB = Workbooks.Open(vFName)
    If oWB Is Nothing Then Exit Sub
    On Error Resume Next
    Set oSheet = oWB.Sheets("Sheet2")
    On Error GoTo 0
    If oSheet Is Nothing Then
    MsgBox "Sheet does not exist."
    Else
    MsgBox "Sheet exists"
    End If
    oWB.Close
    End Sub
    </pre>

    Legare Coleman

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •