gpt4 book ai didi

vba - 打印动态命名范围

转载 作者:行者123 更新时间:2023-12-04 21:02:29 25 4
gpt4 key购买 nike

我有一份我正在尝试使用 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

最佳答案

我认为这与 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

关于vba - 打印动态命名范围,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33487730/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com