Consulting

Results 1 to 7 of 7

Thread: Failing to open existing workbook

  1. #1
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location

    Failing to open existing workbook

    I made a little function to check if a workbook is open and I stepped through it and the path and everything is correct and it is throwing no errors but the workbook is still not opening:

    [VBA]Public Function OWB(wb As String)
    Dim pathO As String
    Dim ExcelApp As Excel.Application
    Set ExcelApp = GetObject(, "Excel.Application")
    On Error Resume Next
    pathO = ThisWorkbook.path & "\" & wb
    Set WB_check = Workbooks(wb)
    If Err <> 0 Then
    On Error GoTo 0
    ExcelApp.Workbooks.Open fileName:=pathO
    End If
    End Function[/VBA]
    ------------------------------------------------
    Happy Coding my friends

  2. #2
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    worked for me...

    [VBA]
    Sub test()

    Dim s As String
    s = "DataFile.xlsx"

    OWB (s)

    End Sub
    [/VBA]
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  3. #3
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    I am trying to run it from as a worksheet function...is that not going to work?
    ------------------------------------------------
    Happy Coding my friends

  4. #4
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    afaik, files cannot be opened via worksheet functions...
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  5. #5
    VBAX Expert CatDaddy's Avatar
    Joined
    Jun 2011
    Posts
    581
    Location
    fck me...theres probably no way around it either huh?
    ------------------------------------------------
    Happy Coding my friends

  6. #6
    VBAX Guru mancubus's Avatar
    Joined
    Dec 2010
    Location
    "Where I lay my head is home" :D
    Posts
    2,644
    i dont know.

    but, as you may know, you can return "true" or "false" in a cell.

    [VBA]
    Public Function IsWorkBookOpen(WorkBookName As String)
    'http://www.vbaexpress.com/kb/getarticle.php?kb_id=186

    Dim WB As Workbook

    On Error Resume Next
    Set WB = Workbooks(WorkBookName)
    On Error Goto 0

    IsWorkBookOpen = Not WB Is Nothing

    End Function
    [/VBA]
    PLS DO NOT PM; OPEN A THREAD INSTEAD!!!

    1) Posting Code
    [CODE]PasteYourCodeHere[/CODE]
    (or paste your code, select it, click # button)

    2) Uploading File(s)
    Go Advanced / Attachments - Manage Attachments / Add Files / Select Files / Select the file(s) (multiple files can be selected while holding Ctrl key) / Upload Files / Done
    Replace company specific / sensitive / confidential data. Include so many rows and sheets etc in the uploaded workbook to enable the helpers visualize the data and table structure. Helpers do not need the entire workbook.

    3) Testing the Codes
    always back up your files before testing the codes.

    4) Marking the Thread as Solved
    from Thread Tools (on the top right corner, above the first message)

  7. #7
    VBAX Expert shrivallabha's Avatar
    Joined
    Jan 2010
    Location
    Mumbai
    Posts
    750
    Location
    Use hyperlinks formula as it will allow you to click on it to open file.

    Or

    Worksheet_Change event.
    Regards,
    --------------------------------------------------------------------------------------------------------
    Shrivallabha
    --------------------------------------------------------------------------------------------------------
    Using Excel 2016 in Home / 2010 in Office
    --------------------------------------------------------------------------------------------------------

Posting Permissions

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