Sunday, March 25, 2012

Access Class Library from Excel 97

Hi All, does anyone know if it's possible to utilise a .NET class
library from Excel 97 ? I've tried but receive a runtime error
-2146232576 which means nothing to me, my class is shown below, I've
placed the assembly into the GAC and registered it using RegAsm all to
no avail
using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;
namespace CallingCSharpFromWord97
{
[ComVisible(true)]
public class PJKWordClass
{
public TextWriter tw = null;
public PJKWordClass()
{
}
public void WriteLogFile(string msg)
{
tw = new StreamWriter("c:\\PJKCalledFromWord97.log", true);
tw.WriteLine(String.Format("This file was created by C# which was
called from a COM client {0} at
{1}",msg,DateTime.Now.ToLongDateString()));
tw.Close();
}
}
}
I can reference the assembly in Excel, but when run, it bombs on the
CreateObject line ( with the error number shown above )
Dim oCSharp As CallingCSharpFromWord97.PJKWordClass
Set oCSharp = CreateObject("CallingCSharpFromWord97.PJKWordClass")
regardsPete Kane wrote:
> Hi All, does anyone know if it's possible to utilise a .NET class
> library from Excel 97 ? I've tried but receive a runtime error
> -2146232576 which means nothing to me, my class is shown below, I've
> placed the assembly into the GAC and registered it using RegAsm all to
> no avail
> using System;
> using System.Collections.Generic;
> using System.Text;
> using System.IO;
> using System.Runtime.InteropServices;
> namespace CallingCSharpFromWord97
> {
> [ComVisible(true)]
> public class PJKWordClass
> {
> public TextWriter tw = null;
> public PJKWordClass()
> {
> }
> public void WriteLogFile(string msg)
> {
> tw = new StreamWriter("c:\\PJKCalledFromWord97.log", true);
> tw.WriteLine(String.Format("This file was created by C# which was
> called from a COM client {0} at
> {1}",msg,DateTime.Now.ToLongDateString()));
> tw.Close();
> }
> }
> }
>
> I can reference the assembly in Excel, but when run, it bombs on the
> CreateObject line ( with the error number shown above )
> Dim oCSharp As CallingCSharpFromWord97.PJKWordClass
> Set oCSharp = CreateObject("CallingCSharpFromWord97.PJKWordClass")
> regards
>
Sorry posted to wrong group :-)sql

No comments:

Post a Comment