Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4,391
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Colon at the end of excel file name(ex: problem.xls:1, problem.xls financeguy New Users to Excel 2 January 15th 10 01:15 AM
Problem viewing Excel 2003 Pivot Chart fields in Excel 2007 ronny B Charts and Charting in Excel 1 October 24th 08 10:08 PM
Weird problem with Excel 2000...Worksheets disappearing in a shared Excel file BrianL_SF Excel Discussion (Misc queries) 2 October 10th 06 08:27 PM
Weird problem with Excel 2000...Worksheets disappearing in a shared Excel file BrianL_SF Excel Programming 6 October 7th 06 08:54 AM
Started out as an Access problem. Now an Excel problem RobertM Excel Discussion (Misc queries) 2 April 26th 06 07:30 PM


All times are GMT +1. The time now is 11:49 AM.

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

About Us

"It's about Microsoft Excel"