Results 1 to 2 of 2

Thread: Using Relative Paths in Declare Statements

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Sep 2006
    Posts
    223

    Using Relative Paths in Declare Statements

    I noticed that VBA is really only happy when I use absolute paths to my homebrewed DLLs, like:

    Code:
    Declare Function myFunction1 Lib "C:\extremely\long\abs\path\to\DLL\myDLL.dll" _
       (argList) As retType
    Declare Function myFunction2 Lib "C:\extremely\long\abs\path\to\DLL\myDLL.dll" _
       (argList) As retType
    Declare Function myFunction3 Lib "C:\extremely\long\abs\path\to\DLL\myDLL.dll" _
       (argList) As retType
    To be honest, that's kind of a drag. Is there any way possible to use relative pathnames here? I'm really just after shortening the declare statement to make it more palatable. Even this would be an improvement:


    Code:
    Const myPath = "C:\extremely\long\abs\path\to\DLL"
    
    Declare Function myFunction1 Lib myPath & "\myDLL.dll" (argList) As retType
    Declare Function myFunction2 Lib myPath & "\myDLL.dll" (argList) As retType
    Declare Function myFunction3 Lib myPath & "\myDLL.dll" (argList) As retType
    Not to mention the fact that if I give someone my Excel document, they only need to change one line to get all the Declare statements to match their own filesystem structure instead of modifying a whole bunch of Declare statements. In this regard, a relative path name to the DLL would be fantastic....

    Is there anything that can be done here to make the declarations a bit more user friendly?

    Thanks!
    Pete

  2. #2
    Super Moderator si_the_geek's Avatar
    Join Date
    Jul 2002
    Location
    Bristol, UK
    Posts
    41,974

    Re: Using Relative Paths in Declare Statements

    Assuming that it works the same way as in Classic VB... As long as you have actually registered the DLL (by running regsvr32, or by compiling it on that machine), you should simply be able to use the file name, with no path at all, eg:
    Code:
    Declare Function myFunction1 Lib "myDLL.dll" (argList) As retType

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width