PDA

View Full Version : vba excel code to find current dll running



thatoneguy
01-12-2009, 02:06 PM
Background info:
We have a excel file that relies on .dll files to run and we update our .dll files to match the excel sheets. A user must manually run the batch program that simply just runs the .dll in the regsvr32. Using the wrong .dll will result in incorrect data and/or crashing of the excel program.

Looking for:
some help with coding in vba that searches for the .dll used and, at the very least, just displays the .dll path in an excel sheet. Although just the filename would be a bigger improvement.

Notes:
I've tried the application.registeredfunctions with an if null statement and it just returns the null value. This is because the .dll is not installed with the excel file. Maybe some code that searches the registry for the file name? The file will be moved based on the user's preference but never renamed. Also, Excel must be closed and the batch file ran, so a shell statement will not work.

Hope to hear from yall soon. Thanks.

Kenneth Hobs
01-12-2009, 03:24 PM
Lots of dll's are running so I am not sure which one you mean. If you mean look for a dll filename, that is easy enough.

Otherwise, you may need something like: http://www.cpearson.com/excel/DLLNameOfComAddin.htm

thatoneguy
01-16-2009, 07:57 AM
Sorry for the late reply but it is a seperate .dll that the user must manually runs through a batch regsvr32 file. As we update our Excel model we also update the .dll for that so each Excel model has its own specific .ddl that corresponds to is. My goal is to show the file name of the .dll ran in a cell so that the user can quickly realize that the wrong .dll has been used and needs to close out Excel and run the correct .dll.

Kenneth Hobs
01-16-2009, 08:36 AM
The easiest way to achieve your goal would be to put a check in your xls's open event. It would run a version function that you exported in your dll and compare it to the version the xls expects.

thatoneguy
01-16-2009, 09:05 AM
Thanks for the help so far...
Ok so what you're saying is put some information in the .dll file used thats unique to the xls version associated to it. Then use the auto open and boolean statements to test the version based upon its true/false feature?

If it's not too much to ask, I've never had to use these statements for this....would it be possible for you to start some of the code so I could get going in the right direction?

Kenneth Hobs
01-16-2009, 09:24 AM
I would show the code for your DLL function but I am not sure what language you are using. Naturally, I prefer vb.net for this kind of thing.

e.g. DLL function called Version:

Function Version() as Double
Return 1.1
End Function
For you xls's Open event, it would go something like:
Private Sub Workbook_Open()
Dim o As YourDLL.YourClass
Set o = New YourDLL.YourClass
If o.Version <> 1.1 Then
MsgBox "The DLL file's version does not equal the version for this xls." _
, vbCritical, "UnMatched DLL Version"
ThisWorkbook.Close
End If
End Sub