Location and declaration of dll

H

hstijnen

Hi,
I'v created a lib (MyLib.dll) and I want to call a sub (Mysub) from that.
Therefor is needed a declaration of the sub/lib:

Declare Sub MySub Lib "C:\map1\map2\MyLib.dll" ( )

This requires full specification of the path to the lib. Now I want make it
more dynamic, for I don't know where the user will place the lib. I want the
user to place the lib in the same map as the Excel sheet. And I want to
declare the sub as:

Declare Sub MySub Lib "MyLib.dll" ( )

So without path.

Now it appears the call only succeeds when the lib is placed in the System32.
What do I have to do to call the lib when it's placed in the same folder as
the sheet?
I'v tried the following code:

Path = ActiveWorkbook.Path
ChDir Path
Call MySub()

But that didn't succeed. Has anybody an idea?

TIA
 
P

Peter T

Normally I would have thought simply changing the current directory to the
folder containing the dll would suffice. I wouldn't use 'Path' as the
variable name though. Might be worth changing ActiveWorkbook.path to
Thisworkbook.path unless 100% sure the wb containing the code is also the
activeworkbook. Perhaps try this API and see if that works

Private Declare Function SetCurrentDirectoryA _
Lib "kernel32" (ByVal lpPathName As String) As Long

SetCurrentDirectoryA Thisworkbook.path
Call MySub

Regards,
Peter T
 
H

hstijnen

Thanks, it works!

Peter T said:
Normally I would have thought simply changing the current directory to the
folder containing the dll would suffice. I wouldn't use 'Path' as the
variable name though. Might be worth changing ActiveWorkbook.path to
Thisworkbook.path unless 100% sure the wb containing the code is also the
activeworkbook. Perhaps try this API and see if that works

Private Declare Function SetCurrentDirectoryA _
Lib "kernel32" (ByVal lpPathName As String) As Long

SetCurrentDirectoryA Thisworkbook.path
Call MySub

Regards,
Peter T
 
P

Peter T

What in particular made it work, changing Activeworkbook to Thisworkbook or
using the API.

Regards,
Peter T
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top