Open RTF File in Word, Set Printer & Print from a VB.net application

robnhood00
robnhood00 used Ask the Experts™
on
I need to open a RTF file in an instance of Word, set the Printer to a Network Printer and then print. I'm using VB.Net 2.0
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Most Valuable Expert 2012
Top Expert 2014

Commented:
You can use process.start to open this file, then sent the print verb to it but i am not sure how you would set the printer.
Commented:
hi
you can with interop

the Point is that you change the printer so
  myWordApp.WordBasic.FilePrintSetup(Printer:="PDFCreator", DoNotSetAsSysDefault:=1)

When you chane with the Propertie ActivePrinter then the Default Printer is changing!!!!!




 Dim myWordApp As Word.Application
            Dim myWordDoc As Word.Document
            myWordApp = New Word.Application
            myWordDoc = myWordApp.Documents.Open("c:\test.rtf")
            myWordApp.WordBasic.FilePrintSetup(Printer:="PDFCreator", DoNotSetAsSysDefault:=1)
            myWordApp.PrintOut()
            System.Runtime.InteropServices.Marshal.ReleaseComObject(myWordDoc)
            myWordDoc = Nothing
            myWordApp.Quit()
            myWordApp = Nothing

Author

Commented:
Thanks... That was quick and clean!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial