PC Review


Reply
Thread Tools Rate Thread

Coring on calling VBA6 dll

 
 
Tom Med
Guest
Posts: n/a
 
      9th Nov 2007
I have this bit of code that cores excel. Is there something I am
doing wrong?

Option Explicit


Declare Function EbExecuteLine Lib "C:\Program Files\Common Files
\Microsoft Shared\VBA\VBA6\VBACV20.dll" ( _
ByVal stStringToExec As Long, _
ByVal Unknownn1 As Long, _
ByVal Unknownn2 As Long, _
ByVal fCheckOnly As Long) As Long


Public Function ExecuteLine(stCode As String, Optional bCheckOnly As
Boolean = False) As Boolean
Dim stCommand As String * 256
Dim lgPtr As Long

stCommand = stCode
lgPtr = StrPtr(stCommand)
ExecuteLine = EbExecuteLine(lgPtr, 0&, 0&, Abs(bCheckOnly)) = 0
End Function


Private Sub test1()
ExecuteLine ("15 + 30")
End Sub

 
Reply With Quote
 
 
 
 
Peter T
Guest
Posts: n/a
 
      9th Nov 2007
If you have a vb6 ActiveX you'd need to register it on the target machine,
eg with Regsrv32. The dll would also need at least one public class and
method.

Your Declare Function is for a C(++/#) dll but not a VB6. Instead you'll
need to start by creating an instance of the class and (typically) attaching
a reference to it. You can do that with CreateObject or, with late binding,
use of 'New'.

Dim mObjCls as Object

on error resume next
Set mObjCls = CreateObject("VBACV20.clsEntry")
if not mObjCls is nothing then
ExecuteLine = mObjCls.EbExecuteLine(lgPtr, 0&, 0&, Abs(bCheckOnly)) = 0

Assuming the dll is registered, set a reference to it in your vba project.
Press F2 and in Object Browser Libraries look for your dll. Hopefully you
will find "EbExecuteLine". Look for its container class name and substitute
with clsEntry in the example.

As, having set the reference, you can use Early binding and do something
like this -

Dim mObjCls as VBACV20.clsEntry ' manually type and look at intellisense
Set mObjCls = New clsEntry
etc

Curiosity - what's the StrPtr(stCommand), if say a to get the address of
something? in a normal module in the dll I'd be interested as to how that
could be used

Regards,
Peter T


"Tom Med" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I have this bit of code that cores excel. Is there something I am
> doing wrong?
>
> Option Explicit
>
>
> Declare Function EbExecuteLine Lib "C:\Program Files\Common Files
> \Microsoft Shared\VBA\VBA6\VBACV20.dll" ( _
> ByVal stStringToExec As Long, _
> ByVal Unknownn1 As Long, _
> ByVal Unknownn2 As Long, _
> ByVal fCheckOnly As Long) As Long
>
>
> Public Function ExecuteLine(stCode As String, Optional bCheckOnly As
> Boolean = False) As Boolean
> Dim stCommand As String * 256
> Dim lgPtr As Long
>
> stCommand = stCode
> lgPtr = StrPtr(stCommand)
> ExecuteLine = EbExecuteLine(lgPtr, 0&, 0&, Abs(bCheckOnly)) = 0
> End Function
>
>
> Private Sub test1()
> ExecuteLine ("15 + 30")
> End Sub
>



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

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

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
File not found vba6.dll rdufour Microsoft Access Form Coding 0 18th Sep 2006 04:58 PM
File Not Found: VBA6.DLL =?Utf-8?B?V0xNUGlsb3Q=?= Microsoft Excel Misc 1 20th Apr 2005 04:31 PM
VBA6.dll =?Utf-8?B?d2FycmVudmJhNg==?= Microsoft Access Form Coding 1 8th Mar 2005 05:05 AM
Why is new install asking for vba6.dll? Alp Microsoft Access VBA Modules 1 15th Oct 2004 09:56 PM
VBA6 error Bryan Microsoft Access VBA Modules 1 8th Feb 2004 01:11 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 05:39 AM.