View Single Post
  #8   Report Post  
Posted to microsoft.public.excel.programming
[email protected] EagleOne@discussions.microsoft.com is offline
external usenet poster
 
Posts: 391
Default Sample VBA code to open an Visual-Studio-2008-created VBA DLL


Chip, I found the following but do not fully comprehend its impact.

Imports System
Imports System.Runtime.InteropServices

<Assembly: ComVisibleAttribute(False)
Namespace InteroperabilityLibrary

<ComVisibleAttribute(False) _
Public Class BaseClass

Sub SomeSub(valueOne As Integer)
End Sub

End Class

' This class violates the rule.
<ComVisibleAttribute(True) _
Public Class DerivedClass
Inherits BaseClass

Sub AnotherSub(valueOne As Integer, valueTwo As Integer)
End Sub

End Class

End Namespace


I learn best if I have a "Template" that can be modified.

One of my challenges is that I never had assess to VB6.

Do you have a template that I could review so that I can get perspective to the task?


I am aware of the following on your site:
http://www.cpearson.com/excel/workbooktimebomb.aspx
http://www.cpearson.com/excel/creatingcomaddin.aspx
http://www.cpearson.com/Excel/creati...nctionlib.aspx

Since I do not have any .NET nor VB6 (just VS 2008 Visual Basic Express), my mind can not make the
leap.

EagleOne


Chip Pearson wrote:



which call a DLL (Excel
VBA-compiled in VS 2008 Visual Basic)


What, exactly, does that mean? Did you create an Excel 2007
code-behind workbook or did you create Class Library DLL?

If you're referring to a DLL created as a class library, that assembly
must have been created as a COM visible assembly. That allows
COM-based applications (VB, VBA, VB6, etc) to call its functions. If
it isn't COM-visible, you won't be able to call its functions. You set
this property from the Assembly Information dialog on the Application
page of the My Project member of your project.

Once you have compiled the DLL as COM-visible, open the VBA editor, go
to the Tools menu, choose References and then Browse. Locate the
typelib file for the DLL (in the same folder as the DLL itself) and
load that typelib. Use the typelib file (assm_name.tlb not
assem_name.dll) rather than the DLL file.

Once you do that, you can call members of the one or more classes that
make up the DLL. For example, if your DLL is named MyExcelDLL.dll and
the class that contains the functions is called MyFunctionClass, you
can call a function, MyRealFunction with code like

Dim MF As MyExcelDLL.MyFunctionClass
Set MF = New MyExcelDLL.MyFunctionClass
Result = MF.MyRealFunction(1234)

With NET dlls, you don't use the Declare statement. That is used only
for Win32 DLLs, such as those created with __stdcall in VC++.

Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)



On Fri, 22 May 2009 09:58:38 -0400,
wrote:

2003, 2007

Possible for someone to provide a few examples written in Excel VBA, which call a DLL (Excel
VBA-compiled in VS 2008 Visual Basic)?

In short, I have the myExcelVBA.DLL but cannot find VBA examples to "call" it properly.

How/Where do I declare the libraries necessary? (Assume I need to use all libraries/references used
to run the VBA from the VBA editor window.

TIA EagleOne