Home |
Search |
Today's Posts |
|
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
A problem when trying to run a dll from Excel / VBA
Hi,
A decade ago, I last ran dlls from the VBA environment. I'm tryin again, and my day of reading, hacking and googling has yeilded only failure for me. When I use Application.Run, it appears that the executable dll is being read as a text file input to the spreadsheets. Here is a test case code, in the .xls file, VBA environment, in the ThisWorkbook module: Option Explicit 'be sure to go to Tools--References and add in the reference to the desired dll/exe/ocx Private Declare Sub Main Lib "C:\Documents and Settings\TestCase \Project1.dll" () Sub TestCase() Application.Run ("C:\Documents and Settings\TestCase\Project1.dll! Main") End Sub I have a Project1.vbp, with a single class module in it, Class1. It is compiled to Project1.dll. The code of Class1 is: Public Sub Main() MsgBox "Main" End Sub When I run TestCase, I get a message box indicating the following lines: This file is not in a recognizable format. If you know the file is from another program which is incompatible with Microsoft Office Excel, click Cancel, ....... If you suspect the file is damaged, click Help for more information about solving the problem. If you still want to see what text is contained in the file, click OK..... If I hit OK, the binary of the dll is read in to a spreadsheet. What am I screwing up? Other info: Excel VBA environment About Microsoft Visual Basic Microsoft Visual Basic 6.3 Version 9972 VBA: Retail 6.4.9972 VB6 environment Microsoft Visual Basic 6.0 For 32-bit Windows Development Version 8176 VBA: Retail 6.0.8169 I'm on an XP system. thanks, Matt |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
A problem when trying to run a dll from Excel / VBA
You seem to be confusing the 2 methods of calling dll.
If the dll is a standard windows dll (not ActiveX), then use the "Declare" method and no reference, then call it: Call Main 'as there are no parameters or return value If the dll is ActiveX (which it looks like as it is created from a .vbp, unless you are doing something fancy to force a standard dll), set a reference, then create an instance: Dim MyClass as Project1.Class1 set myclass=new Project1.Class1 myclass.main In neither case do you need Application.Run. You may want to look at Excel Addins (xla) or possibly COM addins also. NickHK "Matt Matt" wrote in message oups.com... Hi, A decade ago, I last ran dlls from the VBA environment. I'm tryin again, and my day of reading, hacking and googling has yeilded only failure for me. When I use Application.Run, it appears that the executable dll is being read as a text file input to the spreadsheets. Here is a test case code, in the .xls file, VBA environment, in the ThisWorkbook module: Option Explicit 'be sure to go to Tools--References and add in the reference to the desired dll/exe/ocx Private Declare Sub Main Lib "C:\Documents and Settings\TestCase \Project1.dll" () Sub TestCase() Application.Run ("C:\Documents and Settings\TestCase\Project1.dll! Main") End Sub I have a Project1.vbp, with a single class module in it, Class1. It is compiled to Project1.dll. The code of Class1 is: Public Sub Main() MsgBox "Main" End Sub When I run TestCase, I get a message box indicating the following lines: This file is not in a recognizable format. If you know the file is from another program which is incompatible with Microsoft Office Excel, click Cancel, ....... If you suspect the file is damaged, click Help for more information about solving the problem. If you still want to see what text is contained in the file, click OK..... If I hit OK, the binary of the dll is read in to a spreadsheet. What am I screwing up? Other info: Excel VBA environment About Microsoft Visual Basic Microsoft Visual Basic 6.3 Version 9972 VBA: Retail 6.4.9972 VB6 environment Microsoft Visual Basic 6.0 For 32-bit Windows Development Version 8176 VBA: Retail 6.0.8169 I'm on an XP system. thanks, Matt |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
A problem when trying to run a dll from Excel / VBA
NickHK!
I would like to thank you and I would like to confirm for anyone else that this is what works when using Excel VBA to call a VB6 dll created via vbp: 'set a reference, then create an instance: Dim MyClass as Project1.Class1 set myclass=new Project1.Class1 myclass.main best regards, Matt |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Colon at the end of excel file name(ex: problem.xls:1, problem.xls | New Users to Excel | |||
Problem viewing Excel 2003 Pivot Chart fields in Excel 2007 | Charts and Charting in Excel | |||
Weird problem with Excel 2000...Worksheets disappearing in a shared Excel file | Excel Discussion (Misc queries) | |||
Weird problem with Excel 2000...Worksheets disappearing in a shared Excel file | Excel Programming | |||
Started out as an Access problem. Now an Excel problem | Excel Discussion (Misc queries) |