"excelobject.Workbooks.Open" suddenly does not work
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
Guys:
I developed some VBA codes that communicate with some excel sheets, and grab the necessary data. These codes has been working great for the past months but all in a sudden, all the lines involving excelobject.workbooks.open fail. The codes will give me an error when running the workbooks.open method: Run-time error: '-2147319765(8002802b)' Automation error Element not found. There is nothing wrong with the path of the excel workbook. I can run the same code without problems by excel vba editor, but when I run it in Inventor or AutoCAD, it fails.
My co-worker had this issue yesterday and he reported to me but I didn't have this issue yesterday. However, after restarting my computer, which means my computer will have some routine updates by the company, the code doesn't work anymore.
I would really appreciate it if anyone can help me debug this.. Thank you all in advance.
Dim oexcelApp As Object
'Try to connect to a running instance of Excel.
On Error Resume Next
Set oexcelApp = GetObject(, "Excel.Application")
oexcelApp.DisplayAlerts = False
If Err Then
Err.Clear
Set oexcelApp = CreateObject("Excel.Application")
oexcelApp.DisplayAlerts = False
If Err Then
MsgBox "Cannot access excel."
Exit Sub
End If
End If
Dim oWb As Workbook
Set oWb = oexcelApp.Workbooks.Open("W:\Model Library\<FOLDER>\PARTS LIST (WEIGHT).xlsx")
If Err Then
MsgBox "Unable to open the Excel document: Weight Spreadsheet."
Exit Sub
End If