Click here to Skip to main content
11,704,044 members (66,420 online)
Rate this: bad
Please Sign up or sign in to vote.
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);
Posted 22-May-11 2:42am
Edited 22-May-11 5:17am
Dalek Dave433.2K
Mark Nischalke at 22-May-11 8:47am
Use code block to format code snippets you post
Dalek Dave at 22-May-11 11:18am
Edited for Grammar and readability.
Rate this: bad
Please Sign up or sign in to vote.

Solution 3

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
Dalek Dave at 22-May-11 11:19am
Sage advice.
Espen Harlinn at 22-May-11 11:30am
Thank you Dalek :)
Abhinav S at 22-May-11 12:14pm
Good point. 5.
Espen Harlinn at 22-May-11 14:29pm
Thanks Abhinav :)
SAKryukov at 22-May-11 12:49pm
Good note, a 5.
Espen Harlinn at 22-May-11 14:29pm
Thanks SAKryukov!
Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Try using interop classes for instantiation as shown here[^].
Khalid Sabtan at 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 at 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 at 22-May-11 10:54am
Good link. my 5
Abhinav S at 22-May-11 12:13pm
Thank you.
SAKryukov at 22-May-11 12:49pm
Agree, a good one, a 5.
Abhinav S at 22-May-11 13:25pm
Thank you SA.

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

  Print Answers RSS
0 Maciej Los 530
1 OriginalGriff 510
2 Sergey Alexandrovich Kryukov 421
3 Andy Lanng 294
4 F-ES Sitecore 220
0 OriginalGriff 8,744
1 Sergey Alexandrovich Kryukov 7,747
2 CPallini 5,107
3 Maciej Los 4,716
4 Mika Wendelius 3,606

Advertise | Privacy | Mobile
Web03 | 2.8.150819.1 | Last Updated 22 May 2011
Copyright © CodeProject, 1999-2015
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100