How to set printer properties using vb.net

I use EDRAW to view Microsoft Word and maybe Print , Preview , ETC.. And I plan to add some features to it. I add 2 buttons for Print Short (8.5 by 11 inches) and Print Long (8.5 by 13 inches) , and I have 2 printers for long and short. How to set printer properties in each button ?. If I press the short button, it will print briefly using printer 1 in the same way as the button, but it is in printer 2.

I follow the code in the link above.

Does anyone have an idea about this ?. Any suggestion helps well and is well received. Thank you .. Greetings .. I will give 50 bonuses to him in two days.

Code as @Hadi request

Here is my button code for printing. A.

 Private Sub btnPrint_Click(sender As System.Object, e As System.EventArgs) Handles btnPrint.Click AxEDOffice1.SetActivePrinter("Printer Name") AxEDOffice1.ActiveDocument.PageSetup.PaperSize = Microsoft.Office.Interop.Word.WdPaperSize.wdPaperA4 AxEDOffice1.PrintDialog() End Sub 

and get an error. An object variable or with a block variable not set in the line of code AxEDOffice1.ActiveDocument.PageSetup.PaperSize = Microsoft.Office.Interop.Word.WdPaperSize.wdPaperA4

0
source share
2 answers

After checking the library, all you have to do is use the SetActivePrinter Method to change the default printer as follows:

  AxEDOffice1.SetActivePrinter("Adobe PDF") 

And to change PaperSize you should use the following

 AxEDOffice1.ActiveDocument.PageSetup.PaperSize = Microsoft.Office.Interop.Word.WdPaperSize.wdPaperA4 

AxEDOffice1.ActiveDocument is an instance of Microsoft.Office.Interop.Word.WordDocumentClass

The code tested it and it works great.

EDIT 1:

An object variable or with an undefined block variable

For more on this, the MSDN article has many suggestions.

EDIT 2:

To print a document directly without showing PrintDialog , you must use the PrintOut function.

 AxEDOffice1.PrintOut(EDOfficeLib.WdPrintOutRange.wdPrintAllDocument) 
+1
source

It looks like Change the printername in PrintDialog with the code to make sure the print dialog pre-selects the printer based on the printer name in vb.net.

0
source

All Articles