C# library called from Excel 2000

How to call C# functions created wth VS2008 from Excel2000 modules

Page 1 of 1

0 Replies - 1805 Views - Last Post: 11 August 2008 - 08:47 AM Rate Topic: -----

#1 SoftwareTester   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 11-August 08

C# library called from Excel 2000

Post icon  Posted 11 August 2008 - 08:47 AM

I want to call functions written in C# using VS2008 from VBA in Excel2000.

I created a new class project in VS2008, checked the "Register for COM interop" option and build the files (in debug mode) creating VBATest.dll, VBATest.tlb and VBATest.pdb.
My C#code is:
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;

namespace VBATest
{
	[Guid("4E238B48-0443-4bbd-93A7-64900E892DC2")]
	[ComVisible(true)]
	public interface ITest
	{
		int getTest();
	}
	[Guid("EAF753AA-AC20-4e5a-B9B6-660C8EDD1F13")]
	[ComVisible(true)]
	public class TestClass : ITest
	{
		public int getTest()
		{
			return 100;
		}
	}
}

In Excel2000 I wrote
Sub MyTest()
	MsgBox GetTestValue()
End Sub

Public Function GetTestValue() As Integer
	Dim a As ITest
	Dim instance As New VBATest.TestClass
	Set a = instance
	GetTestValue = a.getTest()
End Function

and I added a reference to VBATest from the 'Tools | References' menu from the Microsoft Visual Basic editor.
I also added a reference to Microsoft DAO 3.6 Library

Using the Object browser (View | Object Browser) I see TestClass being defined WITHOUT any members and I see ITest defined having member getTest

Running MyTest I receive a runtime error (Automation error) at [CODE]Set a = instance[/CODE}

What is wrong and how can I make it work

Attached image(s)

  • Attached Image


Is This A Good Question/Topic? 0
  • +

Page 1 of 1