-
February 16th, 2010, 11:56 PM
#1
Calling a dll in VBA
Hi All,
I am making a makro for an excel file and having some problem calling the function in a dll file. My dll file is located in the same directory as my excel file. I am using the below statement.
Private Declare Function Des Lib "Des.dll" (ByVal sMsg As String, ByVal sKey As String, ByVal sRet As String, ByVal iAction As Integer) As Integer
I can use the function if I specify the complete path to the dll. However I understand that if I keep the dll file with the excel file then I can use "Des.dll" instead of using a complete path to the file like "C:\New Folder\Des.dll"
Any help would be a lot appreciated.
Thanks,
AQ
-
February 17th, 2010, 03:56 AM
#2
Re: Calling a dll in VBA
Welcome to the Forums!
At a guess, I'd say that you have to register the Des.dll file on the system first. You could do this by using RegSvr32.exe. Also remember to make sure you copy the Des.dll file in the Windows/System directory.
I hope it helps!
-
February 17th, 2010, 11:45 AM
#3
Re: Calling a dll in VBA
In most cases dlls are not to register.
Putting them in the Windows\System or System32 folder should help, though.
Having the dll in the same folder as the excel sheet will possibly not help, if excel starts with its own folder as default directory.
It could however work, if you add your folder where the dll resides to the PATH environment variable.
-
February 18th, 2010, 03:43 AM
#4
Re: Calling a dll in VBA
Thanks Hannes and WoF for the reply,
I actually got an excel file and the "Des.dll" from my friend. His macro in his Excel sheet runs perfectly fine calling the "Des.dll".
No matter where I place his excel sheet, if the Des.dll is with the file, everything runs perfectly well. In his case, I never registered the "Des.dll". Or to put it in a Windows folder.
So I am unable to understand why the same is not doing any good for me.
-
February 19th, 2010, 08:45 AM
#5
Re: Calling a dll in VBA
Two questions:
What are the differences between the excel sheets?
Are there different versions of excel on the two computers?
-
February 21st, 2010, 12:11 AM
#6
Re: Calling a dll in VBA
Hi WoF
There is only one computer.
The only difference I can think of is that the first file came from a friend of mine and it may be written with a old version of MS Excel.
I am using Office 2007.
But would it create any difference to how the macro should behave ?
-
February 22nd, 2010, 09:43 AM
#7
Re: Calling a dll in VBA
I think it is not the behaviour of the macro, but maybe the behaviour of the newer version of excel...
I can't say for sure. How do you load the excel sheet? By double clicking on it or by first starting excel and then loading the sheet?
-
February 23rd, 2010, 08:43 PM
#8
Re: Calling a dll in VBA
Just by double clicking on the sheet. Is there something called default path where vb would search for the dll. Can I somehow see that path in my program ?
-
February 24th, 2010, 09:46 AM
#9
Re: Calling a dll in VBA
VB knows the app object.
The property app.path would hold the application path where the exe was started in.
I'm not sure if VBA has an app object, too. Never tried that.
You could try something like Text1.Text=app.path, having put a textbox somewhere.
-
February 24th, 2010, 02:54 PM
#10
Re: Calling a dll in VBA
Pretty sure it's Application.Path in VBA
-
February 24th, 2010, 08:21 PM
#11
Re: Calling a dll in VBA
Thanks for the replies guys,
So I checked on two things ....
ThisWorkbook.path -> Would return the path where my workbook is
Application.path -> Would return me the path where excel.exe is
So I placed the "des.dll" where excel.exe was ...... and bravo ..... it worked. But still I am not sure how do I use this information for my purpose. I need the file "des.dll" beside my workbook so that I can publish my workbook.
Somehow I cannot use any string variables in place of "Des.dll" for below mentioned statement
Private Declare Function Des Lib "Des.dll" () As Integer
-
February 24th, 2010, 10:39 PM
#12
-
February 28th, 2010, 10:12 PM
#13
Re: Calling a dll in VBA
Hi dglienna,
Thanks for the post. Yups I have been through this msdn article. But this post reiterates the same thing. I can register my dll using the declare statement. But I cannot somehow make the relative addressing work, so that everytime my function can read the dll from the directory where the excel sheet co-resides.
-
February 28th, 2010, 10:39 PM
#14
Re: Calling a dll in VBA
Create a macro that self-registers the .dll
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|