ワークブックに印刷するシートごとに 1 回呼び出される Excel VBA 印刷関数があります。
VBA でシートを循環し、この関数を呼び出します。
Sub PrintSheet
With ActiveSheet
'lastRow is worked out here....
'Autofit YTD and SLY
.Columns("J:J").AutoFit
.Columns("K:K").AutoFit
'Autofit email column
.Columns("F:F").AutoFit
With .PageSetup
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = False
.Orientation = xlLandscape
.LeftMargin = Application.InchesToPoints(0.4)
.RightMargin = Application.InchesToPoints(1)
.TopMargin = Application.InchesToPoints(0.5)
.BottomMargin = Application.InchesToPoints(0.5)
.RightFooter = "&P of &N"
.PrintArea = "$A$1:$O$" & CStr(lastRow)
End With
.PrintOut
End With
End Sub
私が抱えている問題は、時々 (ランダムな動作で、常に同じシートであるとは限りません)、自動調整している列が非常に広く伸びて、他の列がページから外れることがあります。これは、印刷ルーチンを再度実行できるため、データ関連ではありません。以前は列をうまく引き延ばしていた同じシートを印刷します。最初にVBAコードで入力されるため、シート内のすべての列の値をトリミングしています
伸びる列は自動調整される列であると言ったことを除けば、この動作のパターンを見つけることができませんでした。
何かご意見は?