Estate Master
Estate Master

Reputation: 193

Excel VBA error when calling DLL "An attempt was made to load a program with an incorrect format"

I have an Excel file that calls a .net DLL (called "MyDLL") in the auto_open VBA macro. When it gets to the 2nd line below, the error below occurs:

--VBA Code--

If objSensitivity Is Nothing Then

Set objSensitivity = CreateObject("MyDLL.Calculations") '<<Crashes here

--Error--

An Error has occured: -2147024885 Automation error An attempt was made to load a program with an incorrect format.

My system is:

Other notes:

Since i know that it worked fine previous to my rebuild, and i know it works for other users running it on Windows 7 64 bit, i can only assume it is something else specific to my PC, and not the actual DLL.

Can anyone help?

Upvotes: 1

Views: 1413

Answers (4)

Estate Master
Estate Master

Reputation: 193

I sorted this out.

I did a repair install of all my versions of Office, as i suspected it was a faulty Microsoft Interop DLL OR for some unknown reason, it was using a 64-bit version of the Interop.

Very weird, but its up an running now.

Upvotes: 3

Bevan
Bevan

Reputation: 44307

Try comparing the PATH environment variable between your machine and one that works.

It's kind of old fashioned - but the search process for finding dependent DLL files still uses the PATH to find files.

If one of the dependencies of MyDLL is somewhere else on the machine (not in the same or a nested directory), a missing PATH directory could defeat the loader.

Upvotes: 0

Hand-E-Food
Hand-E-Food

Reputation: 12794

64-bit processes cannot load 32-bit code and vica-versa. Have you tried Excel x64?

Upvotes: 0

Bevan
Bevan

Reputation: 44307

The VBA CreateObject() call is used to instantiate COM objects. Has the DLL in question been properly registered to create the appropriate registry entries?

Upvotes: 0

Related Questions