Consulting

Results 1 to 6 of 6

Thread: How do I Check if a workbook is opened??

  1. #1
    VBAX Contributor Daxton A.'s Avatar
    Joined
    Jun 2004
    Location
    Biloxi, Mississippi
    Posts
    143
    Location

    Question How do I Check if a workbook is opened??

    check all the workbook names that are open if it isn't it opens it.

  2. #2
    BoardCoder
    Licensed Coder
    VBAX Expert mark007's Avatar
    Joined
    May 2004
    Location
    Leeds, UK
    Posts
    622
    Location
    If I read this right you want to check if a specific workbook is open and if not to open it?

    If so then use the following:


    Dim wb As Workbook
    On Error Resume Next
    Set wb=application.workbooks("WorkbookName.xls")
    On Error Goto 0 'now reset error handling
    If wb Is Nothing Then 
        application.workbooks.open("Path to file\WorkbookName.xls")
    end if

    "Computers are useless. They can only give you answers." - Pablo Picasso
    Mark Rowlinson FIA | The Code Net

  3. #3
    Moderator VBAX Master Tommy's Avatar
    Joined
    May 2004
    Location
    Houston, TX
    Posts
    1,184
    Location
    Just another way to skin the cat


    Sub FindWrkBk(PathToWorkbook As String, WrkBook As String)
        Dim IsThere As Boolean
        Dim Wrkbk As Workbook
        IsThere = False
        For Each Wrkbk In Workbooks
        If Wrkbk.Name = WrkBook Then
            IsThere = True
        End If
        Next
        If Not IsThere Then
        Application.Workbooks.Open PathToWorkbook & "\" & WrkBook
        End If
    End Sub
    
    Sub does()
    FindWrkBk "C:\WINDOWS\Desktop\stuff", "class.xls"
    End Sub

  4. #4
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    ~Anne Troy

  5. #5
    BoardCoder
    Licensed Coder VBAX Expert mark007's Avatar
    Joined
    May 2004
    Location
    Leeds, UK
    Posts
    622
    Location
    I was looking for that before but couldn't find it!

    "Computers are useless. They can only give you answers." - Pablo Picasso
    Mark Rowlinson FIA | The Code Net

  6. #6
    Site Admin
    The Princess VBAX Guru Anne Troy's Avatar
    Joined
    May 2004
    Location
    Arlington Heights, IL
    Posts
    2,530
    Location
    My bad. I mass-moved some stuff to the wrong place.
    ~Anne Troy

Posting Permissions

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