下面的代码是我不仅需要设置打印区域,还要设置页边距以及页面适合一页的代码。这段代码被包装成一个for循环,在该工作之前和之后有很多其他部分就好了(所以它不是'Next i'在错误的地方)。此代码仅适用于第一次迭代,不适用于任何其他迭代(每次迭代都包含用于创建工作正常的新工作表的代码)。
为什么这只能工作一次?如何让它在所有迭代中工作?
Application.PrintCommunication = True
ActiveSheet.PageSetup.PrintArea = Range(Cells(1, 1), Cells(53, 29)).Address
Application.PrintCommunication = False
With ActiveSheet.PageSetup
.LeftHeader = ""
.CenterHeader = ""
.RightHeader = ""
.LeftFooter = ""
.CenterFooter = ""
.RightFooter = ""
.LeftMargin = Application.InchesToPoints(0.5)
.RightMargin = Application.InchesToPoints(0.5)
.TopMargin = Application.InchesToPoints(0.5)
.BottomMargin = Application.InchesToPoints(0.5)
.HeaderMargin = Application.InchesToPoints(0.5)
.FooterMargin = Application.InchesToPoints(0.5)
.PrintHeadings = False
.PrintGridlines = True
.PrintComments = xlPrintNoComments
.PrintQuality = 600
.CenterHorizontally = False
.CenterVertically = False
.Orientation = xlLandscape
.Draft = False
.PaperSize = xlPaperLetter
.FirstPageNumber = xlAutomatic
.Order = xlDownThenOver
.BlackAndWhite = False
.Zoom = False
.FitToPagesWide = 1
.FitToPagesTall = 1
.PrintErrors = xlPrintErrorsDisplayed
End With