Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Ref: <a href="http://social.msdn.microsoft.com/forums/en-US/vsto/thread/45152591-1f3e-4d1e-b767-ef030be9d9f2" rel="nofollow noreferrer">http://social.msdn.microsoft.com/forums/en-US/vsto/thread/45152591-1f3e-4d1e-b767-ef030be9d9f2</a></p> <p>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:</p> <pre><code>private void ThisAddIn_Startup(object sender, System.EventArgs e) { Application app = Globals.ThisAddIn.Application; Word.Document doc = app.ActiveDocument; foreach (Section section in doc.Sections) { section.PageSetup.PaperSize = WdPaperSize.wdPaperA4; } } </code></pre> <p>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.</p> <p><strong>EDIT: This does work</strong>, I dont know what you mean with the comment <code>ThisAddIn isnt a member or Globals and ActiveDocument isnt a member of Application in VB.NET</code> - you cant skip these top two lines, here is the VB.Net version:</p> <pre><code>Private Sub ThisAddIn_Startup(sender As Object, e As System.EventArgs) Dim app As Application = Globals.ThisAddIn.Application Dim doc As Word.Document = app.ActiveDocument For Each section As Section In doc.Sections section.PageSetup.PaperSize = WdPaperSize.wdPaperA4 Next End Sub </code></pre> <p>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:</p> <p><img src="https://i.stack.imgur.com/0tdr3.png" alt="enter image description here"></p> <p>The only issue you may face is when the Printer doesn't have the size paper you get this error: <code>Requested PaperSize is not available on the currently selected printer.</code></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload