Click here to Skip to main content
15,608,157 members
Please Sign up or sign in to vote.
4.33/5 (3 votes)
I could not declare Word successfully in this program.

I could not print the document.

I have referenced ms word 2007 but did not know how to declare Word.

See part of my program below
private ApplicationClass wrdApp = null;// new ApplicationClass();
       private Document oDataDoc = null;// new Document();
       //Word.Selection wrdSelection; //word2003
       Selection wrdSelection;//2007

       private void SendToPrinterAcopy(string DocFile)
           Object background = true;
           Object append = false;
           //Object range = Word.WdPrintOutRange.wdPrintAllDocument;
           //Object item = Word.WdPrintOutItem.wdPrintDocumentContent;
           //Object pageType = Word.WdPrintOutPages.wdPrintAllPages;
           Object range = wrdApp.WdPrintOutRange.wdPrintAllDocument;  //<------Error
           Object item = wrdApp.WdPrintOutItem.wdPrintDocumentContent;//<------Error
           Object pageType = wrdApp.WdPrintOutPages.wdPrintAllPages;  //<------Error
           Object copies = 1;//one copy only
           Object printToFile = false;
           oDataDoc.PrintOut(ref background, ref append,
           ref range, ref missing, ref missing, ref missing,
           ref item, ref copies, ref missing, ref pageType,
           ref printToFile, ref missing, ref missing,
           ref missing, ref missing,ref missing, ref missing,
           ref missing);
Updated 22-May-11 5:17am
[no name] 22-May-11 8:47am    
Use code block to format code snippets you post
Dalek Dave 22-May-11 11:18am    
Edited for Grammar and readability.

Apart from Abhinav S reference: if your application is executing as a 64-bit process you will run into trouble as Word 2007 is a 32-bit program ...

Best regards
Espen Harlinn
Share this answer
Dalek Dave 22-May-11 11:19am    
Sage advice.
Espen Harlinn 22-May-11 11:30am    
Thank you Dalek :)
Abhinav S 22-May-11 12:14pm    
Good point. 5.
Espen Harlinn 22-May-11 14:29pm    
Thanks Abhinav :)
Sergey Alexandrovich Kryukov 22-May-11 12:49pm    
Good note, a 5.
Try using interop classes for instantiation as shown here[^].
Share this answer
Khalid Sabtan 22-May-11 9:18am    
i have use those
//private ApplicationClass wrdApp2 = new ApplicationClass();
//private word = new Microsoft.Office.Interop.Word.Application;
none of them work
Khalid Sabtan 22-May-11 9:23am    
it seems to me it should works,i should not have to write
Object range = Word.WdPrintOutRange.wdPrintAllDocument;
Object item = Word.WdPrintOutItem.wdPrintDocumentContent;
Object pageType = Word.WdPrintOutPages.wdPrintAllPages;
i should do like this
Object range = WdPrintOutRange.wdPrintAllDocument;
Object item = WdPrintOutItem.wdPrintDocumentContent;
Object pageType = WdPrintOutPages.wdPrintAllPages;
Espen Harlinn 22-May-11 10:54am    
Good link. my 5
Abhinav S 22-May-11 12:13pm    
Thank you.
Sergey Alexandrovich Kryukov 22-May-11 12:49pm    
Agree, a good one, a 5.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900