Click here to Skip to main content
Rate this: bad
good
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 3:42am
Edited 22-May-11 6:17am
Dalek Dave432.9K
v3
Comments
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
good
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
  Permalink  
Comments
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.
--SA
Espen Harlinn at 22-May-11 14:29pm
   
Thanks SAKryukov!
Rate this: bad
good
Please Sign up or sign in to vote.

Solution 1

Try using interop classes for instantiation as shown here[^].
  Permalink  
Comments
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.
--SA
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 OriginalGriff 6,569
1 Sergey Alexandrovich Kryukov 6,168
2 DamithSL 5,228
3 Manas Bhardwaj 4,717
4 Maciej Los 4,150


Advertise | Privacy | Mobile
Web01 | 2.8.1411022.1 | Last Updated 22 May 2011
Copyright © CodeProject, 1999-2014
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