Use DOTNET assembly in Word 97

P

Pete Kane

Hi All, is it possible to utilise a .NET class library in Word 97 ? I've
tried without success, my test class and VBA macro are shown below


using System;
using System.Collections.Generic;
using System.Text;
using System.IO;
using System.Runtime.InteropServices;

namespace CallingCSharpFromWord97
{

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();
}

}
}


Sub Button1_Click()
Dim obj As CallingCSharpFromWord97.PJKWordClass

Set obj = CreateObject("CallingCSharpFromWord97.PJKWordClass")
obj.WriteLogFile "MS Word"

Set obj = Nothing

End Sub

I have set a reference to the assembly in the VBA editor but I receive a
COM error -2146232576 (80131700)Automation error when I run it - which
means nothing to me
 
N

Nicholas Paldino [.NET/C# MVP]

Pete,

I see nothing in your class which indicates that you are prepping it for
use in a COM environment. Check out the section of the MSDN documentation
titled "Exposing .NET Framework Components to COM", located at:

http://msdn2.microsoft.com/en-us/library/zsfww439(VS.71).aspx

This will give you the details of what you need to do in code, and in
deployment, to expose your .NET programs to COM.
 

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