Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the problem in this statement?

I am writing a sample application to convert a DOC file into a PDF. While doing this I'm getting an error.

// Creating the instance of WordApplication
MSDOC = new Microsoft.Office.Interop.Word.ApplicationClass();
try
{
    MSDOC.Visible = false;
    MSDOC.Documents.Open(ref Source, ref Unknown,
     ref Unknown, ref Unknown, ref Unknown,
     ref Unknown, ref Unknown, ref Unknown,
     ref Unknown, ref Unknown, ref Unknown,
     ref Unknown, ref Unknown, ref Unknown, ref Unknown, ref Unknown);
    MSDOC.Application.Visible = false;
    MSDOC.WindowState = Microsoft.Office.Interop.Word
                                 .WdWindowState.wdWindowStateMaximize;
    object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;
}
catch (Exception ex)
{
    MessageBox.Show(ex.Message, "Message from Sample");
}

And this is the statement I am getting an error at:

object format = Microsoft.Office.Interop.Word.WdSaveFormat.wdFormatPDF;

Error Interop type 'Microsoft.Office.Interop.Word.ApplicationClass' cannot be embedded. Use the applicable interface instead.

like image 483
Hemant Kumar Avatar asked Oct 11 '10 14:10

Hemant Kumar


2 Answers

Have you tried doing what the error message suggests? Replace

MSDOC = new Microsoft.Office.Interop.Word.ApplicationClass();

with

Microsoft.Office.Interop.Word.Application MSDOC;
MSDOC = new Microsoft.Office.Interop.Word.Application();
like image 173
Dirk Vollmar Avatar answered Nov 15 '22 18:11

Dirk Vollmar


Try MSDOC = new Microsoft.Office.Interop.Word.Application(); instead of .ApplicationClass().

like image 40
jball Avatar answered Nov 15 '22 17:11

jball



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!