Andreas Barth
asked on
Cannot create an instance of an abstract class or interface Microsoft Office Interop Word Application
Cannot create an instance of an abstract class or interface Microsoft Office Interop Word Application
Office 2007 Visual Studio 2008 C# Windows Forms
Office 2007 Visual Studio 2008 C# Windows Forms
using System;
using System.Collections.Generic;
using System.Collections;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Drawing.Printing;
using System.Text;
using System.Windows.Forms;
using Word = Microsoft.Office.Interop.Word;
using Office = Microsoft.Office.Core;
using System.Runtime.InteropServices;
using System.Threading;
try
{
Microsoft.Office.Interop.Word.Application word = null; Microsoft.Office.Interop.Word.Document doc = null;
word = new Microsoft.Office.Interop.Word.Application();
object missing = System.Type.Missing;
string filen;
filen = @"c:\\Complaints\\" + this.lnTextBox.Text + "_" + this.fnTextBox.Text + ".docx";
object fileName = filen;
object falseValue = false;
object trueValue = true;
word.Visible = true;
word.Activate();
doc = word.Documents.Add(ref missing, ref missing, ref missing, ref trueValue);
string wordcleaning;
wordcleaning = "HISTORY OF ILLNESS:\n\n";
Word.Range range = null;
object startPosition = 0;
object endPosition = 0;
range = doc.Range(ref startPosition, ref endPosition);
range.Text = insertText;
doc.SaveAs(ref fileName, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
}
catch (System.Runtime.InteropServices.COMException exword3) { MessageBox.Show("Error accessing Word document."); }
ASKER
thx for your answer. The link is where I have the code originally from.
ASKER CERTIFIED SOLUTION
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
I've found an example here on how to use the Word.Application class here:
http://www.builderau.com.au/program/dotnet/soa/Easily-utilise-Microsoft-Word-functionality-in-your-NET-application/0,339028399,339198903,00.htm