打印一个dynamic的命名范围

我有一个报告,我正在尝试使用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