简体   繁体   中英

Method 'Open' of object 'Workbooks' failed

here is a very small piece of code. I tested and worked for office 03, 07, 10 versions without a problem. but on one machine running Win7 and Office 2007 fails always on this line:

Set oWB = oExcel.Workbooks.Open("C:\myFile.xls")

Method 'Open' of object 'Workbooks' failed

what is the possible solution? PS file is not damaged.

Dim oExcel As Excel.Application
Dim oWB As Workbook
Dim oWS As Worksheet
Dim rRng As Excel.Range

Application.ScreenUpdating = False
Set oExcel = New Excel.Application
Set oWB = oExcel.Workbooks.Open("C:\myFile.xls")
Set oWS = oExcel.Worksheets(2)
Set rRng = oWS.Range("C01:C500")
oExcel.Visible = False

thanks everyone.

I found the solution, Foxit reader add-in in word was causing the trouble. once removed everything worked.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM