dll declaration without path?

  • Hello!


    I'll try to explain my question; I have an .xls file and its vba code includes a dll declaration. Everything's working fine when I place the whole path in dll declaration

    Code
    Private Declare Sub ECDISP_DLL Lib  _
    "C:\Documents and settings\Athina\Desktop\UNCOM_DLL\Release\ECDISP_DLL" ()


    What I want is to mention no path and yet the program to be able to find the .dll.
    What are my options? Does anyone have a clue?


    Thanks a lot in advance for your time and suggestions!


    Athina

  • Re: dll declaration without path?


    If you do not specify a path for libname, Visual Basic will search for the file in the following order:
    1. Directory containing the .exe file
    2. Current directory
    3. Windows 32-bit system directory \Windows\System32
    4. Windows directory \Windows
    5. Path environment variable


    So what you need to do is have your Dll registered in one of the above locations.

  • Re: dll declaration without path?


    Thank you for your suggestions!


    I would like you to explain to me what do you mean by
    "If you do not specify a path for libname.."
    Could you be more specific (by writing the code) because I have some problems when I try to apply it?


    Let me tell you!
    When I write

    Code
    Private Declare Sub ECDISP_DLL ()


    I get
    "Compile error
    Expected: Lib"


    So, I write

    Code
    Private Declare Sub ECDISP_DLL Lib()


    but then I get
    "Compile error:
    Expected: string constant"


    So, I think of adding an empty string and write

    Code
    Private Declare Sub ECDISP_DLL Lib "" ()


    I get no compile error, but when I run the program I get
    "Run-time error '53':
    File not found:"


    Then I take an idea from the first suggestion and write

    Code
    Private Declare Sub ECDISP_DLL Lib "\\ECDISP_DLL" ()


    again I get no compile error, but when I run the program I get
    "Run-time error '53':
    File not found:\\ECDISP_DLL"



    I would appreciate any suggestions about the error messages or the main problem!


    Thank you a lot for your time!


    Athina

  • Re: dll declaration without path?


    Sorry, again!


    It works fine, only when the "Default File Location" field in Options is empty; when there is a path it emerges the classic error message '53' file not found, although the .dll file remains at the same location (in the same folder as the excel file).


    Any ideas?


    I appreciate your time and patience!


    Athina

  • Re: dll declaration without path?


    Thanks again for your help!
    Your suggestions have been really valuable!
    It worked fine!
    I hope I will be able to help you that much some day!


    Thank you once more for your time and patience!


    Athina

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!