我有一个报告,我正在尝试使用VBA脚本进行打印。我需要在一页(肖像)上打印报告并使其居中。我有格式化下来拍,但范围导致我的问题。我需要将打印范围设置为调整为指定范围内的值的数量。现在,它将打印命名范围,但如果添加或删除了条目,它将不会调整大小或打印扩展或缩小范围。
Sub PrintFailureReport()
Sheets("Failure Report").Activate
Range("FailReportPrintArea").Select
ActiveSheet.PageSetup.PrintArea = Selection.Range("FailReportPrintArea").Address
Application.PrintCommunication = True
With ActiveSheet.PageSetup
.LeftMargin = Application.InchesToPoints(0.25)
.RightMargin = Application.InchesToPoints(0.25)
.TopMargin = Application.InchesToPoints(0.25)
.BottomMargin = Application.InchesToPoints(0.25)
' .HeaderMargin = Application.InchesToPoints(0.3)
' .FooterMargin = Application.InchesToPoints(0.3)
.PrintGridlines = False
.CenterHorizontally = True
.CenterVertically = True
.Orientation = xlPortrait
.PaperSize = xlPaperLetter
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
.BlackAndWhite = True
End With
Range("FailReportPrintArea").PrintOut
End Sub
答案 0 :(得分:0)
我认为在设置地址之前没有添加Application.PrintCommunication = False
Sub PrintFailureReport()
Sheets("Failure Report").Activate
Range("FailReportPrintArea").Select
Application.PrintCommunication = False
ActiveSheet.PageSetup.PrintArea = Selection.Range("FailReportPrintArea").Address
Application.PrintCommunication = True
With ActiveSheet.PageSetup
.LeftMargin = Application.InchesToPoints(0.25)
.RightMargin = Application.InchesToPoints(0.25)
.TopMargin = Application.InchesToPoints(0.25)
.BottomMargin = Application.InchesToPoints(0.25)
' .HeaderMargin = Application.InchesToPoints(0.3)
' .FooterMargin = Application.InchesToPoints(0.3)
.PrintGridlines = False
.CenterHorizontally = True
.CenterVertically = True
.Orientation = xlPortrait
.PaperSize = xlPaperLetter
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
.BlackAndWhite = True
End With
Range("FailReportPrintArea").PrintOut
End Sub