VB.Net DLL Using Excel Named Ranges

S

ShockWave

Hello and Help!

I have created a .Net DLL using the following in VB.Net:

Imports Excel
<ComClass(NameSpaceClass.ClassId, NameSpaceClass.InterfaceId
NameSpaceClass.EventsId)> _
Public Class NameSpaceClass

#Region "COM GUIDs"
' These GUIDs provide the COM identity for this class
' and its COM interfaces. If you change them, existing
' clients will no longer be able to access the class.
Public Const ClassId As String
"DD3F5A18-99E3-4797-8004-B61A6013466F"
Public Const InterfaceId As String
"EB6EBB23-0528-48F9-AF68-7FD23B25FF10"
Public Const EventsId As String
"672CB2A1-C839-4157-97E7-EB73B430ADCB"
#End Region

' A creatable COM class must have a Public Sub New()
' with no parameters, otherwise, the class will not be
' registered in the COM registry and cannot be created
' via CreateObject.
Public Sub New()
MyBase.New()
End Sub

Dim xlApp As Excel.Application
Dim xlBook As Excel.Workbook
Dim xlSheet As Excel.Worksheet

'Dim ktfn As Excel.Range
Public Function showNum() As Single
showName
CType(xlApp.ActiveWorkbook.Application.Range("ExcelValue").Value
Single)
End Function
End Class


\VB.Net

Now I have also some code as follows in an Excel VBA Module:


Option Explicit
Option Base 1
Global ExcelValue As Range
Dim NameSpaceInstance As New NameSpacePlayer.NameSpaceClass


Function showNum() As Single
showNum = NameSpaceInstance .showNum
End Function

Function vbaNum() As Single
vbaNum = Range("ExcelValue").value
End Function

/VBA


what these two should do is return the value of a cell name
ExcelValue. ExcelValue can be any single cell such as A1 on Sheet1 o
B40 on Sheet 2...the cell name, ExcelValue, is global so that it can b
moved if needed without modifying any written code. With VBA this work
because of the integration between Excel and VBA but it has been
challenge getting my VB.Net COM DLL to get with the program.

Does anyone have any ideas
 
J

Jamie Collins

ShockWave wrote ...
I have created a .Net DLL
<snip>
what these two should do is return the value of a cell named
ExcelValue.
Does anyone have any ideas?

Consider using ADO.NET.

Jamie.

--
 
S

ShockWave

Yes, I've considered that but another thing to take note is that th
workbook is shared and I want the users be allowed to change its nam
and location etc. With ADO.Net I'll have to code in where to make th
connection.

What it comes down to is, I need to somehow make the DLL know whic
application it needs to be refering to. With MS Office Tools for VS.Ne
2003, there is such a qualifier called "ThisApplication" whereby wit
it, I can just say "ThisApplication.Range("Whatever").Value" . BU
here's the problem, I'm developing for Office 2002 and so can't use th
nice tool set for VS.net.

Still looking for help! Thanks
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top