Tell me more ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free, no registration required.

I've been trying to print out a some pages from a word document created from a template. I use the Word.Printout() method, but I just can't figure out how to use the Word.PrintOut(From: X, To: X). I just can't seem to get it right. Can any body help me? :-)

Object oMissing = System.Reflection.Missing.Value;
Object oTemplatePath = @"C\batch_template.dotx";
Microsoft.Office.Interop.Word.Application wordApp = new Microsoft.Office.Interop.Word.Application();
Document wordDoc = new Document();
wordDoc = wordApp.Documents.Add(ref oTemplatePath, ref oMissing, ref oMissing, ref oMissing);
Object myFrom = "1";
Object myTo = "5";
wordDoc.SaveAs("myFile.doc");
wordDoc.Range(myFrom, myTo);
wordApp.Documents.Open("myFile.doc");
wordApp.PrintOut();

Thanks!

share|improve this question
2  
Does the MSDN entry for Document.PrintOut help? (Untested: wordDoc.PrintOut(Range: WdPrintOutRange.wdPrintFromTo, From: myFrom, To: myTo)) – Corak Jun 3 at 9:21
Just saw the light thanks to you @Corak - couldn't see the forest for all the trees. :-) Object myFrom = "1"; Object myTo = "5"; wordDoc.SaveAs("myFile.doc"); wordApp.Documents.Open("myFile.doc"); wordApp.PrintOut(Range: WdPrintOutRange.wdPrintFromTo, From: myFrom, To: myTo); THANKS! – Asger Jun 3 at 9:49

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.