0

Excel file won't open in MS Access.

This piece of code was working until a few days ago. Now it's NOT erroring out and it's not creating any Excel objects.

Dim XL As Object
Set XL = New Excel.Application
XL.workbooks.Open(ourPath)

The Object assignment should work (the path is correct, I've checked it multiple times).

braX
  • 11,506
  • 5
  • 20
  • 33
user6879637
  • 41
  • 1
  • 3
  • 1
    First you do not assign the workbook and you need to make the Excel application [visible](https://learn.microsoft.com/en-us/office/vba/api/excel.application.visible) else it runs in background. Also where is your error handling to catch errors? Please include full code block. – Parfait Jun 12 '19 at 19:51
  • Today I had a new development, it seems like Filecopy and shell commands are also not executing on this database. and they don't even error out. – user6879637 Jun 13 '19 at 20:50

2 Answers2

0

Since you are using early binding, perhaps you are missing the reference to the Microsoft Excel Object library (Tools > References), or perhaps this library has been rendered as MISSING as a result of opening your database in an earlier version of MS Access.

Nevertheless, to avoid the reliance on references entirely and rule this out as a possible cause, you could try using late binding e.g.:

Dim XL As Object
Set XL = CreateObject("Excel.Application")
XL.Workbooks.Open(ourPath)
Lee Mac
  • 15,615
  • 6
  • 32
  • 80
  • I think that was what original piece of code was. The most surprizing part is the same code is working on a co-worker's machine, which is mind boggling and makes me think some switch got flipped somewhere when as part of some patch, but I can't locate it. And he and I have the refrences checked. – user6879637 Jun 12 '19 at 19:13
  • maybe you have no permissions to access this file on your machine? – Van Ng Jun 13 '19 at 08:01
  • Nope...The excel file and mdb file are in same locations. This code was actually working up until a few days ago. – user6879637 Jun 13 '19 at 18:09
0

So what was happening was, the excel files had add-ins that were preventing for excel to be opened properly. The code worked like a charm as soon as those add-ins were disabled.

Dharman
  • 30,962
  • 25
  • 85
  • 135
user6879637
  • 41
  • 1
  • 3