What is the problem with this statement?

I am writing an example application for converting a DOC file to a PDF file. In doing so, I get an error message.

// 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 in which I get the error message:

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

An error like Interop 'Microsoft.Office.Interop.Word.ApplicationClass' cannot be built-in. Use applicable interface.

+7
c # ms-word
source share
3 answers

Have you tried to do what the error message suggests? Replace

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

from

 Microsoft.Office.Interop.Word.Application MSDOC; MSDOC = new Microsoft.Office.Interop.Word.Application(); 
+14
source share

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

+6
source share

if you do not need special word processing in words, do as 0xA3 recommended otherwise leave ApplicationClass as it is, but go to the project link: select MIcrosoft.Office.Interop.Word, properties and change the built-in form Ture to False Be sure to add office.dll from office 2003 or PIA

0
source share

All Articles