LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 4
Default VB and C# compilation differences

First I appologise for cross posting. I put this in the C# group and then
discovered this group which is probably more appropriate. Anyway, can
someone please explain the following for me...

I am trying to link to a .NET DLL from Excel. Excel needs to pass a
reference to itself to the DLL and then the DLL needs to perform some work
on the running instance of Excel via that reference. As an example, a VB
DLL to return the path to the current active workbook contains the following
(in addition to the COM GUIDS automatically added to a new COMClass)...

Public Class Class1
Public Sub New()
MyBase.New()
End Sub
Private gExcel As Object
Public Property Excel() As Object
Set(ByVal value As Object)
gExcel = value
End Set
Get
Excel = gExcel
End Get
End Property
Public Function Path() As String
Return Excel.ThisWorkbook.Path
End Function
End Class

After adding a refernece to the DLL, a macro in Excel could call this as
follows

Sub VBTest()
Dim VBTest As New VBExcelTest.Class1
Set VBTest.Excel = Application
Debug.Print VBTest.Path
End Sub

This all work fine

How can I do the same thing using C#? If I try to create a DLL with
equivalent(?) code eg

public class Class1
{
public Class1(){
}
private object gExcel;
public object Excel{
get{
return gExcel;
}
set{
gExcel = value;
}
}
public string Path(){
return Excel.ThisWorkbook.Path;
}
}

I get a compile error saying that - 'object' does not contain a definition
for 'ThisWorkbook'

How can I get this to work?

Thanks

Alan



 
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
Post Compilation Packaging StephenAccountant Setting up and Configuration of Excel 0 February 22nd 06 02:59 AM
After each new dll compilation I have to set the reference to the dll in Excel again. Oscar Excel Programming 3 June 5th 05 10:14 PM
VBA Excel compilation error + Z + Excel Programming 1 January 15th 05 05:54 PM
Compilation error question Nathan Gutman Excel Programming 7 December 5th 03 07:54 PM
Conditional compilation WK Excel Programming 1 August 18th 03 01:05 AM


All times are GMT +1. The time now is 03:43 AM.

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

About Us

"It's about Microsoft Excel"