Consulting

Results 1 to 6 of 6

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

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

    Question Solved: 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
    619
    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:

    [vba]
    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
    [/vba]

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

  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

    [VBA]
    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
    [/VBA]

  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
    619
    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 | Professional Office Developers Association

  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
  •