Link to home
Create AccountLog in
Avatar of Andreas Barth
Andreas BarthFlag for United States of America

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
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."); }

Open in new window

Avatar of philipjonathan
philipjonathan
Flag of New Zealand image

To the best of my knowledge, you cannot instantiate an abstract class with the new keyword.
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
Avatar of Andreas Barth

ASKER

thx for your answer.  The link is where I have the code originally from.
ASKER CERTIFIED SOLUTION
Avatar of philipjonathan
philipjonathan
Flag of New Zealand image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer