A Microsoft Excel forum. ExcelBanter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » ExcelBanter forum » Excel Newsgroups » Excel Programming
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

Calling DLL functions in Excel VBA



 
 
Thread Tools Display Modes
  #1  
Old April 17th 07, 05:23 AM posted to microsoft.public.excel.programming
sunny
external usenet poster
 
Posts: 8
Default Calling DLL functions in Excel VBA

I made a dll and I used it in VBA
Like this:
Declare Function currentMilli Lib "exceltest.dll" () As Long

It's working on my computer in any folders.
But when I tried it on other's computer it worked only in the "My
documents" folder.
I expected that it would work if the dll file and the excel file are
in the same folder.
What on earth is going on? How can I make it available on other's
computer in any folders?
Thanks in advance.

Ads
  #2  
Old April 17th 07, 06:17 AM posted to microsoft.public.excel.programming
NickHK
external usenet poster
 
Posts: 4,391
Default Calling DLL functions in Excel VBA

Windows will search for a dll in a number of places. IIRC:
- the %System% dir
- in the folders listed by the PATH enviroment > Debug.Print Environ("PATH")
- in the folder containing the calling component

So put your dll in one of the above location for windows to be able to
locate it.

You can also fully qualify the path the dll if you know/control where it is
installed:
Declare Function currentMilli Lib "C:\exceltest.dll" () As Long

As a side note, if you will be passing string to/from the dll, you should be
aware of the way that Excel/VBA differ in how strings are handled.
If called from the worksheet, you should use a W (Wide) version of the
function call as Excel uses Unicode.
Called from VBA, you can use an A (ANSI) version and let VBA handle string
conversion, which may not advisable as you seem to be from Korea and may not
be using only Ansi text and/or single byte char sets.
Alternative, look into the use of a W version and handling the strings
yourself with Byte arrays/StrConv.

This may help, in the section "ANSI vs. Unicode and the Alias Clause"
http://www.awprofessional.com/articl...&seqNum=3&rl=1

NickHK

"sunny" > wrote in message
ups.com...
> I made a dll and I used it in VBA
> Like this:
> Declare Function currentMilli Lib "exceltest.dll" () As Long
>
> It's working on my computer in any folders.
> But when I tried it on other's computer it worked only in the "My
> documents" folder.
> I expected that it would work if the dll file and the excel file are
> in the same folder.
> What on earth is going on? How can I make it available on other's
> computer in any folders?
> Thanks in advance.
>



  #3  
Old April 17th 07, 08:59 AM posted to microsoft.public.excel.programming
sunny
external usenet poster
 
Posts: 8
Default Calling DLL functions in Excel VBA

I tested with my dll file and excel file in the same folder. (I think
this is the third case)
And the result was just as I said - It worked only in the "My
document" on others' computer.
I don't think it is a good idea to put my dll into System folder and
it is not possible to tell everybody to set their PATH variable
(People are not familiar with setting environment variables)
Maybe I can specify an absolute path of the dll file and let people
copy the file to that path.
If anyone have better ways, just tell me.
Thanks, anyway.

  #4  
Old April 17th 07, 09:13 AM posted to microsoft.public.excel.programming
NickHK
external usenet poster
 
Posts: 4,391
Default Calling DLL functions in Excel VBA

<Surmise>
I would imagine that the folder calling would be that containing Excel, or
possibly the VB/VBA runtime. The location of your XL file would not matter.
</Surmise>

You could avoid the whole path problem by making an ActiveX dll instead and
using COM. Then the location is irrelevant.

NickHK

"sunny" > wrote in message
oups.com...
> I tested with my dll file and excel file in the same folder. (I think
> this is the third case)
> And the result was just as I said - It worked only in the "My
> document" on others' computer.
> I don't think it is a good idea to put my dll into System folder and
> it is not possible to tell everybody to set their PATH variable
> (People are not familiar with setting environment variables)
> Maybe I can specify an absolute path of the dll file and let people
> copy the file to that path.
> If anyone have better ways, just tell me.
> Thanks, anyway.
>



  #5  
Old April 17th 07, 09:51 AM posted to microsoft.public.excel.programming
Peter T
external usenet poster
 
Posts: 5,600
Default Calling DLL functions in Excel VBA

> I expected that it would work if the dll file and the excel file are
> in the same folder.


Not sure but try this

sCurDir = CurDir
ChDir ThisWorkbook.Path
nResult = currentMilli
ChDir sCurDir

Regards,
Peter T

"sunny" > wrote in message
ups.com...
> I made a dll and I used it in VBA
> Like this:
> Declare Function currentMilli Lib "exceltest.dll" () As Long
>
> It's working on my computer in any folders.
> But when I tried it on other's computer it worked only in the "My
> documents" folder.
> I expected that it would work if the dll file and the excel file are
> in the same folder.
> What on earth is going on? How can I make it available on other's
> computer in any folders?
> Thanks in advance.
>



  #6  
Old April 17th 07, 01:56 PM posted to microsoft.public.excel.programming
Robin Hammond[_3_]
external usenet poster
 
Posts: 45
Default Calling DLL functions in Excel VBA

Is the DLL registered on the target machine?

--
Robin Hammond
www.enhanceddatasystems.com


"NickHK" > wrote in message
...
> <Surmise>
> I would imagine that the folder calling would be that containing Excel, or
> possibly the VB/VBA runtime. The location of your XL file would not
> matter.
> </Surmise>
>
> You could avoid the whole path problem by making an ActiveX dll instead
> and
> using COM. Then the location is irrelevant.
>
> NickHK
>
> "sunny" > wrote in message
> oups.com...
>> I tested with my dll file and excel file in the same folder. (I think
>> this is the third case)
>> And the result was just as I said - It worked only in the "My
>> document" on others' computer.
>> I don't think it is a good idea to put my dll into System folder and
>> it is not possible to tell everybody to set their PATH variable
>> (People are not familiar with setting environment variables)
>> Maybe I can specify an absolute path of the dll file and let people
>> copy the file to that path.
>> If anyone have better ways, just tell me.
>> Thanks, anyway.
>>

>
>



 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Calling functions developed in VSTO 2005 from Office Excel 2003 Neil Janabi Excel Programming 0 March 16th 06 10:50 AM
Calling VBA add-in functions/subs from another Excel file. Bret Holle Excel Programming 1 September 17th 04 01:43 AM
Excel 2000 calling functions in C++ um Excel Programming 13 June 2nd 04 11:31 PM
Calling Excel array functions in VBA JM[_4_] Excel Programming 7 March 2nd 04 03:23 AM
Calling functions from Excel worksheets and the Find function in XL '97 Mike-hime Excel Programming 1 January 8th 04 03:17 AM


All times are GMT +1. The time now is 10:37 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2014, Jelsoft Enterprises Ltd.
Copyright 2004-2014 ExcelBanter.
The comments are property of their posters.