VBA - Declare - Finding the Lib File - Windows Registry?
-
Hi All I have a Microsoft Excel Add-in written in VBA. It includes a function that calls a .dll via a Declare statement along the lines of: Declare Function SOMEFUNCTION Lib "c:\Program Files\SomeFunction.dll" (ByVal SomeNo as Double) as Double Instead of including the full path to the Lib file such as "c:\Program Files\SomeFunction.dll", it is possible to register the SomeFunction.dll in the Windows Registry so that I can avoid the fiddly process of finding the path to the file so the Declare Statement becomes: Declare Function SOMEFUNCTION Lib "SomeFunction.dll" (ByVal SomeNo as Double) as Double Is that right? How do you register a .dll with Windows Registry? Is the REGEDIT.ex the only way? Is there some other way? Any suggestions or thoughts on this would be much appreciated. Thanks JS
-
Hi All I have a Microsoft Excel Add-in written in VBA. It includes a function that calls a .dll via a Declare statement along the lines of: Declare Function SOMEFUNCTION Lib "c:\Program Files\SomeFunction.dll" (ByVal SomeNo as Double) as Double Instead of including the full path to the Lib file such as "c:\Program Files\SomeFunction.dll", it is possible to register the SomeFunction.dll in the Windows Registry so that I can avoid the fiddly process of finding the path to the file so the Declare Statement becomes: Declare Function SOMEFUNCTION Lib "SomeFunction.dll" (ByVal SomeNo as Double) as Double Is that right? How do you register a .dll with Windows Registry? Is the REGEDIT.ex the only way? Is there some other way? Any suggestions or thoughts on this would be much appreciated. Thanks JS
Well, VBA is a little limited in this respect. You can't register library .DLL's like you can COM .DLL's. Also, you can't change the location of your reference at runtime in VBA, so putting the path to the .DLL in the Registry isn't going to help much. If you don't want to put the full path to the .DLL in your declaration, you're limited to putting the .DLL where it can be found without it. The best place to put the .DLL is in the directory your code is launched from, usually in Program Files\myAppFolder. You could also put it in C:\WINDOWS, or more acurately, %SystemRoot%. If your .DLL is not in the current directory, the loader then tries to find your .DLL in the each folder listed in the PATH environment variable. If it's not found in the PATH, your function call will fail miserably. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
Well, VBA is a little limited in this respect. You can't register library .DLL's like you can COM .DLL's. Also, you can't change the location of your reference at runtime in VBA, so putting the path to the .DLL in the Registry isn't going to help much. If you don't want to put the full path to the .DLL in your declaration, you're limited to putting the .DLL where it can be found without it. The best place to put the .DLL is in the directory your code is launched from, usually in Program Files\myAppFolder. You could also put it in C:\WINDOWS, or more acurately, %SystemRoot%. If your .DLL is not in the current directory, the loader then tries to find your .DLL in the each folder listed in the PATH environment variable. If it's not found in the PATH, your function call will fail miserably. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome
-
Many thanks Dave - That sheds much light - It's a shame that the Program Folder can't be reached as effortlessly as the Windows folder - Thanks again - JGS
Wanna bet? %ProgramFiles% Try typing SET at a CMD prompt. RageInTheMachine9532 "...a pungent, ghastly, stinky piece of cheese!" -- The Roaming Gnome