Im working with vb.net and microsoft word using Microsoft.Office.Interop.Word and everything is fine. My only problem is I cant find a way to change the default page size printing setting from “letter” to “A4”.
This code was doing the job for Crystal reports but isnt doing it for Word
Dim pp As New System.Drawing.Printing.PrintDocument
For i = 0 To pp.DefaultPageSettings.PrinterSettings.PaperSizes.Count - 1
If pp.DefaultPageSettings.PrinterSettings.PaperSizes.Item(i).Kind = System.Drawing.Printing.PaperKind.A4 Then
pp.DefaultPageSettings.PaperSize = pp.DefaultPageSettings.PrinterSettings.PaperSizes.Item(i)
Exit For
End If
Next
Ref: http://social.msdn.microsoft.com/forums/en-US/vsto/thread/45152591-1f3e-4d1e-b767-ef030be9d9f2
Since page size can vary from section to section, the best thing is to set the PageSetup properties of the Document.Section object. For example, you can loop through all the sections of the document:
Adding locic to set paper size when a document is created or opened is up to you, I’m guessing you’ll need to determine if the document being opened has purposely been saved in a non-A4 size.
EDIT: This does work, I dont know what you mean with the comment
ThisAddIn isnt a member or Globals and ActiveDocument isnt a member of Application in VB.NET– you cant skip these top two lines, here is the VB.Net version:All you need to do is > Visual Studio > Create a New Prorject > Office > Word 2010 (or 2007) Add-In and paste in the above code. Here is a screenshot showing it works with A4 and Letter:
The only issue you may face is when the Printer doesn’t have the size paper you get this error:
Requested PaperSize is not available on the currently selected printer.