0

I am using EDRAW to browse a Microsoft Word and can be Print , Preview , ETC... And I am planning to add some features to it. I am adding 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 the properties of the printers in each button?. If I click button short it will print short using printer 1 same as the button long but it is in printer 2.

I am following the code in the Link provided above.

Anyone has an idea about it?. Any suggestion well help and well be accepted. Thanks.. Cheers.. I will give a 50 bounty to it after two days..

Code as @Hadi request

Here is my button code for print.

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 getting an error Object variable or With block variable not set in the line code of AxEDOffice1.ActiveDocument.PageSetup.PaperSize = Microsoft.Office.Interop.Word.WdPaperSize.wdPaperA4

4
  • 1
    VB.NET is not vba - please read the tag text and remove the one that doesnt apply Commented Nov 28, 2016 at 1:26
  • @Plutonix sorry about it. Commented Nov 28, 2016 at 1:36
  • Possible duplicate of How to set MS Word page size via the automation API? Commented Dec 4, 2016 at 13:16
  • @Kira you are putting a user answer into your question. i think that people can read his answer. By the way it not a good thing to change your questioon every time get answered. Commented Dec 6, 2016 at 15:43

2 Answers 2

1
+50

After Checking the library all you have to do is using SetActivePrinter Method to change your default printer like the following:

 AxEDOffice1.SetActivePrinter("Adobe PDF")

And to change PaperSize you have to use the following

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

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

Code tested it and it works fine.

EDIT 1:

Object variable or With block variable not set

Read more about it on this MSDN article there are many suggestions.

EDIT 2:

To Print your document directly without showing PrintDialog you have to use PrintOut Function.

AxEDOffice1.PrintOut(EDOfficeLib.WdPrintOutRange.wdPrintAllDocument)
Sign up to request clarification or add additional context in comments.

5 Comments

I got an error.. Value of type Boolean cannot be converted to System.Windows.Form.PrintDialog
I got this error "Object variable or With block variable not set." in the paper size
you still there?.. You're the one who almost got my problem :(
@Kira i tested my code and it worked fine. Can you provide us the code you wrote.
Ow man :D I focus on print button and I forgot to open first a document that I want to print. Is there a code that direct print? no need to show a dialog print?.
0

It looks like Change printername in PrintDialog through code deals with making sure a print dialog box pre-selects the printer based on printer name in vb.net.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.