print area is zoom to 120% unless rows not fitting on one page

ThomasOES

Board Regular
Joined
Aug 29, 2017
Messages
174
I print out instructions for lab work. Usually just a few rows and the 120% zoom is my preffered size.
However, sometimes there are many more rows and the 120% zoom would run into another page.
If I simply use the option in vba code to print to 1 page tall and 100% zoom then the print size is always to small.
What I'm trying to do is always use the maximum zoom. Any way to set zoom to auto?
Heres my code. Any help would be appreciated.
VBA Code:
Sub seqprt()
'PRINT PREVIEW FOR SEQUENCE CHART
Sheets("Key").Select
Range("B1", Range("H100").End(xlUp)).Name = "SeqChart"
With Sheets("Key").PageSetup
    .PrintArea = SeqChart
    .LeftHeader = "&""Arial,bold""&10" _
                    & Range("Instrument") _
                    & "  " _
                    & Range("Program")
    .RightHeader = "&""Arial,Bold""&12" _
                    & Range("Operator") _
                    & "    " _
                    & "&""Arial,Bold""&10" & Range("Date")
    .LeftMargin = Application.InchesToPoints(0.3)
    .RightMargin = Application.InchesToPoints(0.3)
    .TopMargin = Application.InchesToPoints(0.5)
    .BottomMargin = Application.InchesToPoints(0.3)
    .HeaderMargin = Application.InchesToPoints(0.3)
    .CenterHorizontally = True
    .Orientation = xlPortrait
    .Draft = True
    .PaperSize = xlPaperLetter
    .BlackAndWhite = True
    .Zoom = 120
    .FitToPagesTall = 1
End With
Range("SeqChart").PrintPreview
ThisWorkbook.Save
Call Show_LotQual_Ctrl
End Sub
 

Excel Facts

Round to nearest half hour?
Use =MROUND(A2,"0:30") to round to nearest half hour. Use =CEILING(A2,"0:30") to round to next half hour.
Will this code help any?

VBA Code:
Sub seqprt()
'PRINT PREVIEW FOR SEQUENCE CHART
  Dim sht As Worksheet
  Dim Pages, PageZoom As Integer
  PageZoom = 200
  
  Set sht = Sheets("Key")
  
  sht.Select
  Range("B1", Range("H100").End(xlUp)).Name = "SeqChart"
  With sht.PageSetup
    .PrintArea = SeqChart
    .LeftHeader = "&""Arial,bold""&10" _
                    & Range("Instrument") _
                    & "  " _
                    & Range("Program")
    .RightHeader = "&""Arial,Bold""&12" _
                    & Range("Operator") _
                    & "    " _
                    & "&""Arial,Bold""&10" & Range("Date")
    .LeftMargin = Application.InchesToPoints(0.3)
    .RightMargin = Application.InchesToPoints(0.3)
    .TopMargin = Application.InchesToPoints(0.5)
    .BottomMargin = Application.InchesToPoints(0.3)
    .HeaderMargin = Application.InchesToPoints(0.3)
    .CenterHorizontally = True
    .Orientation = xlPortrait
    .Draft = True
    .PaperSize = xlPaperLetter
    .BlackAndWhite = True
    .Zoom = PageZoom
    '.FitToPagesTall = 1  Changed this out
  End With
  Application.ScreenUpdating = False
    sht.Activate
    ActiveWindow.View = xlPageBreakPreview
    ActiveWindow.View = xlNormalView
    Pages = fGetPageCount(sht)
    Do While ((PageZoom > 100) And (Pages > 1))
      DoEvents
      PageZoom = PageZoom - 1
      sht.PageSetup.Zoom = PageZoom
      ActiveWindow.View = xlPageBreakPreview
      ActiveWindow.View = xlNormalView
      Pages = fGetPageCount(sht)
    Loop
    Set sht = Nothing
  Application.ScreenUpdating = True
  Range("SeqChart").PrintPreview
  ThisWorkbook.Save
  Call Show_LotQual_Ctrl
End Sub

Public Function fGetPageCount(sht As Worksheet) As Integer
  With sht
    If .PageSetup.PrintArea <> "" Then
      fGetPageCount = (.HPageBreaks.Count + 1) * (.VPageBreaks.Count + 1)
    Else
      fGetPageCount = 0
    End If
  End With
End Function
 
Upvote 0
Alternatively, with the instructions only in a few rows, increase the font size on your worksheet so at 100% zoom it prints as large as you like it to be. Then use...
VBA Code:
        .Zoom = False
        .FitToPagesTall = 1

So at 100% zoom it prints the size you want, and .FitToPagesTall will zoom it down if needed.
 
Last edited:
Upvote 0
Alternatively, with the instructions only in a few rows, increase the font size on your worksheet so at 100% zoom it prints as large as you like it to be. Then use...
VBA Code:
        .Zoom = False
        .FitToPagesTall = 1

So at 100% zoom it prints the size you want, and .FitToPagesTall will zoom it down if needed.
Thanks Frog
I'll add code to increase font size to the print area.
 
Upvote 0

Forum statistics

Threads
1,215,854
Messages
6,127,342
Members
449,377
Latest member
CastorPollux

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