Excel VBA can't open Workbook

后端 未结 7 1700
有刺的猬
有刺的猬 2020-12-11 07:48

First: I\'m using Excel 2007, but the code has to work for Excel 2003 as well.

My problem is the following: I need to access cells in a different workbook, which may

7条回答
  •  渐次进展
    2020-12-11 07:53

    You can check the error in a proper way by using the following code:

    filelocation = c:\whatever\file.xlsx
    
    On Error GoTo Handler 'this is key as if the next row returns an error while opening the file it will jump to the Handler down there.
    Set wkb2 = Workbooks.Open(filelocation, ReadOnly)
    
    Handler:
    MsgBox "File " & filelocation & " does not exist or cannot be reached, please review and try again"
    

    I know that this does not answer the question (that's why I also landed in this thread, as I cannot open the file and can't understand why is that so)

    Cheers, RV

提交回复
热议问题