VBA fit to 1 page width ONLY

nicnad

Board Regular
Joined
Sep 12, 2011
Messages
199
Hi,

I am struggling to make a worksheet fit to one page width only.

If I use the following code :

Code:
    With ActiveWorkbook.Sheets(2).PageSetup
        .LeftHeader = ""
        .CenterHeader = ""
        .RightHeader = ""
        .LeftFooter = ""
        .CenterFooter = ""
        .RightFooter = ""
        .PrintQuality = 600
        .CenterHorizontally = False
        .CenterVertically = False
        .Orientation = xlLandscape
        .Draft = False
        .PaperSize = xlPaperLetter
        .FirstPageNumber = xlAutomatic
        .Order = xlDownThenOver
        .BlackAndWhite = False
        .FitToPagesWide = 1

The page width is not set to 1 page

If I use this one :

Code:
    With ActiveWorkbook.Sheets(2).PageSetup
        .LeftHeader = ""
        .CenterHeader = ""
        .RightHeader = ""
        .LeftFooter = ""
        .CenterFooter = ""
        .RightFooter = ""
        .PrintQuality = 600
        .CenterHorizontally = False
        .CenterVertically = False
        .Orientation = xlLandscape
        .Draft = False
        .PaperSize = xlPaperLetter
        .FirstPageNumber = xlAutomatic
        .Order = xlDownThenOver
        .BlackAndWhite = False
        .Zoom = False
        .FitToPagesWide = 1
        .FittoPagesTall = 0

I get an error on .FittoPagesTall = 0 line

What is the proper way to write this?
 
Last edited:

Excel Facts

Copy PDF to Excel
Select data in PDF. Paste to Microsoft Word. Copy from Word and paste to Excel.
Try changing
.FittoPagesTall = 0
to
Code:
.FitToPagesTall = False
but strictly speaking you should only need
Code:
Sub Macro2()
With ActiveSheet.PageSetup
    .Zoom = False
        .FitToPagesWide = 1
    End With
End Sub
 
Upvote 0
Thank you for the quick reply.

The following code works great. Thanks for the tips :

Code:
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = False

Regards.
 
Upvote 0
This has been a big challenge for me - I used the macro recorder to fit to one page, and got well over 50 lines of code - it's like when I use the recorder for formatting, and I get a ton of code - but that's ok, because I know what I can eliminate.... but I run these samples, and nothing happens - is there something I should be doing / running other code, perhaps, before ?
 
Upvote 0

Forum statistics

Threads
1,214,525
Messages
6,120,052
Members
448,940
Latest member
mdusw

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top