Reputation: 11
Having some difficulty... I have VBA code in Excel to open MS Word and change the page size to a custom size. I cannot get it to work, I've googled a few different ways to try it, I don't do this often and I think I'm missing something.
Dim objWord
Dim objDoc
Dim objRange
Dim objSelection
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Add
Set objSelection = objWord.Selection
objDoc.PageSetup.PageWidth = InchesToPoints(11.5)
objDoc.PageSetup.PageWidth = InchesToPoints(14.375)
<...rest of code>
objWord.Visible = True
At this point, I have tried "objDoc.PageSetup.PageWidth" as shown above, and I've also tried "objSelection.PageSetup.PageWidth" and "objWord.ActiveDocument.PageSetup.Pagewidth" - but it just keeps opening up an 8.5" x 11" letter paper document.
Upvotes: 0
Views: 5409
Reputation: 21
I use custom paper sizes. Unfortunately Word appears to set all of these to papersize 41 However, at least in my case, when I set paperzize to 41 and then change the margins to a specific size, the papersize name is correct
This worked for me
activedocument.PageSetup.PaperSize = 41
activedocument.PageSetup.PageWidth = InchesToPoints(4.25)
activedocument.PageSetup.Pageheight = InchesToPoints(5.5)
Upvotes: 0
Reputation: 196
You can set your custom page size like the following command;
objDoc.PageSetup.PaperSize = 9
If you want to set Word size with A4, you should set 9. If you want to set Word size with A5, you should set 11.
Enumerations;
Upvotes: 1
Reputation: 3032
This works for me
Dim objWord
Dim objDoc
Dim objRange
Dim objSelection
Set objWord = CreateObject("Word.Application")
Set objDoc = objWord.Documents.Add
Set objSelection = objWord.Selection
objDoc.PageSetup.PageWidth = objWord.InchesToPoints(11.5)
objDoc.PageSetup.PageWidth = objWord.InchesToPoints(14.375)
objWord.Visible = True
It still says letter, but the actual size is different -
Note your code has pagewidth
twice, no height.
using -
objDoc.PageSetup.PageHeight = objWord.InchesToPoints(14.375)
Upvotes: 2
Reputation: 824
Does this work:
objDoc.PageSetup.PaperSize = xlPaperA4
The built-in paper sizes can be found here: Excel Paper Sizes
One of these might be close to your custom size.
Upvotes: 0