VBA To Set selected print area Fit to 1 page and then check For zoom/visibility

excelsishya

Board Regular
Joined
Jul 25, 2010
Messages
107
Hi all,

Does anyone have VBA code which will set selected print area to Land scape, fit to 1 page then will check for zoom if it is very small below 30, it will adjust it 50 and making row 3 and column B to repeat.

I am able to get most of things in recorded macro but checking for zoom after fitting print area to 1 page and then changing it to adjust to 50 if zoom is not 30 i am unable to get.

Excel 2007

Thanks
 

Excel Facts

Square and cube roots
The =SQRT(25) is a square root. For a cube root, use =125^(1/3). For a fourth root, use =625^(1/4).
Peter, I think you're having problems similar to those I had with the alternative code in my earlier reply.

Try the test again with the same range, then run the code twice and view the preview.
Thanks Jason. Certainly some varied & unpredictable results. I'm not sure of a solution at this stage.
 
Upvote 0
A rather crude 'fix' but it appears to work, although I haven't tested thoroughly.

Code:
Sub test()
Dim btest As Boolean
Line1:
With ActiveSheet.PageSetup
    .PrintTitleRows = "$3:$3"
    .PrintTitleColumns = "$B:$B"
    .Zoom = False
    .Orientation = xlLandscape
    .FitToPagesWide = 1
    .FitToPagesTall = 1
 
    ExecuteExcel4Macro ("PAGE.SETUP(,,,,,,,,,,,,{#N/A,#N/A})")
    If .Zoom < 30 Then
        .Zoom = 50
    btest = False
    Else
        .Zoom = False
        .FitToPagesWide = 1
        .FitToPagesTall = 1
    btest = (btest = False)
    End If
 
End With
If btest Then GoTo Line1
End Sub

Any thoughts Peter?
 
Upvote 0
VBA To Add Page Footer Not Working Correctly

My apologies didn't mean to post on here
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,243
Messages
6,170,967
Members
452,371
Latest member
Frana

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