2
votes

I have a problem referencing DLL with my VBA code.

My objective is: I have a dll file, code written in C++ (i guess so) and compiled. I have no idea what is coded in there. I have to access this dll from my VBA code, get the result from the dll. My input for the dll is 3 integer values which are in a excel sheet.

I have declared the dll like this Public Declare Function quadratic Lib "C:...\Desktop\Test\quadratic.dll" (ByVal a As Integer, ByVal b As Integer, ByVal c As Integer) As Double (... three dot is just window dir)

On a button click, I read the input values a,b,c from the sheet and call the function passing the arguments like getvalue = quadratic(a, b, c)

  1. I get Microsoft Visual Basic error when running the script, saying "Run-time error '48': File not found: C:...\Desktop\Test\quadratic.dll"

  2. After this I tried to reference this dll using Tools->Reference->Browse and then mapping the dll file kept on my desktop, I get a Microsoft Visual Basic for Application error saying Can'd add a reference to the specified file.

  3. I tried to register the DLL using cmd prompt with command regsvr32 C:...\dllname.dll, which give below error "LoadLibrary("C:\Documents") failed - The specific module could not be found"

  4. I tried to register the DLL with 2nd method on cmd prompt with command rundll32.exe C:...\dllname.dll, which give below error "Error Loading C:\Documents. The specific module could not be found"

I have no clue how to solve this. I tried various ways by changing the VB code, but no joy.

I need, 1. How to reference it using VBA script? 2. How to find the problem in DLL why I cant reference it in VBA?

Please help me at the earliest as it is very urgent.

Regards, Kabilan

1

1 Answers

0
votes

It's difficult to diagnose the problem without knowing more about the Dll and the file structure you're working with, but it looks as though the Dll is currently in a directory under 'My Documents' or similar. Remember that DOS does not handle spaces automatically - you need to add double-quotes.

Try running the register command again, but this time surrounding the path with quotes, e.g.

regsvr32 "C:\Documents and Settings\dllname.dll"

Assuming this works, should be able to reference the Dll in the manner you specified in step 2.