Custom Paper Size

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Custom Paper Size

Post by adam »

Hi anyone,

I'm trying to create a custom paper size using Vba. Following is the code I have so far.

Code: Select all

Sub Print()
Worksheets("Certificate").PageSetup.PaperSize = xlPaperUser(8.27)x(11.8)
Worksheets("Certificate").PrintPreview
End Sub
The above code does not work with the custom size as mention in the code. But it does work with the default paper sizes.

I've set a custom paper size as
adam
8.27" x 11.8" from the page setup menu.

and I want to print this setup from vba code. Any help on this would be kindly appreciated.
Best Regards,
Adam

User avatar
HansV
Administrator
Posts: 78487
Joined: 16 Jan 2010, 00:14
Status: Microsoft MVP
Location: Wageningen, The Netherlands

Re: Custom Paper Size

Post by HansV »

Try the following:

In Excel, on the Page Layout tab of the ribbon, click the arrow in the lower right corner of the Page Setup group.
In the Page Setup dialog, select your custom paper size, then click OK.
Activate the Visual Basic Editor.
Activate the Immediate window (Ctrl+G).
Type the following, then press Enter:

Code: Select all

? Activesheet.PageSetup.Papersize
You should see a number. Use that in your code.
Best wishes,
Hans

User avatar
adam
SilverLounger
Posts: 2347
Joined: 23 Feb 2010, 12:07

Re: Custom Paper Size

Post by adam »

Thanks for the help Hans. Much appreciated.
Best Regards,
Adam