我正在尝试设置一个大约 3000 行的 Excel 工作表,以便很好地打印到 PDF 文件。我正在尝试将页面设置为适合 1 个页面宽度,并且我想根据存储在数组中的行号来修改水平分页符PgBreakRowsArr
。
在我运行附加的子例程后,分页符设置得很好,但打印宽度已从 ~85% 缩小到 ~45%,并以页面大小的 50% 左右打印。
有任何想法吗 ?
代码
Option Explicit
Sub SetFriendlyPrintArea(Sht As Worksheet)
'======================================================================================================================
' Description : Sub sets the Friendly Print Area.
' It loop through 'PgBreakRowsArr' array, and per rows stored inside sets the page breaks.
'
' Argument(s) : sht As Worksheet
'
' Caller(s) : Sub RawDataToByTimeReport (Excel_to_byTime_Report Module)
'======================================================================================================================
Dim LastRow As Long, i As Long
Dim VerticalPageCount As Long, HPageBreakIndex As Long
HPageBreakIndex = 1 ' reset pg. break index
Application.ScreenUpdating = False
With Sht
.Activate
LastRow = FindLastRow(Sht)
With .PageSetup
.PrintArea = "$A$1:I" & LastRow
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
' .PaperSize = xlPaperLetter
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = UBound(PgBreakRowsArr) + 1
End With
ActiveWindow.View = xlPageBreakPreview ' switch to Page Break view to set page breaks
' Debug.Print .HPageBreaks.Count
' loop through array and create Page Breaks according to array's rows
For i = 1 To UBound(PgBreakRowsArr) - 1
Set .HPageBreaks(i).Location = Range("A" & PgBreakRowsArr(i))
Next i
' --- last one need to add it (not move existing one) ---
.HPageBreaks.Add Before:=Range("A" & PgBreakRowsArr(i))
ActiveWindow.View = xlNormalView ' go back to normal view
End With
Application.ScreenUpdating = True
End Sub