Excel 的打印功能(使用 VBA)非常慢。我希望有人有办法加快打印速度(不使用 Excel 4 宏技巧)。我现在是这样做的:
Application.ScreenUpdating = False
With ActiveSheet.PageSetup
-various setup statements which I've already minimized-
End With
ActiveSheet.PrintOut
Application.ScreenUpdating = True
最佳答案
是的,设置 PageSetup 属性时速度非常慢。
您已经设置了 Application.ScreenUpdating = False
,这很好,但在这种情况下同样(或更)重要的一步是设置 Application.Calculation = xlCalculationManual
。 (最好保存这些设置,然后在最后将其恢复为原始设置。)
此外,每个PageSetup属性的属性获取都非常快,而只有属性设置却如此缓慢。因此,您应该测试新的属性设置,以确保它与现有属性值不同,以防止不必要的(且昂贵的)调用。
考虑到这一切,您应该能够使用如下所示的代码:
Dim origScreenUpdating As Boolean
origScreenUpdating = Application.ScreenUpdating
Application.ScreenUpdating = False
Dim origCalcMode As xlCalculation
origCalcMode = Application.Calculation
Application.Calculation = xlCalculationManual
With ActiveSheet.PageSetup
If .PrintHeadings <> False Then .PrintHeadings = False
If .PrintGridlines <> False Then .PrintGridlines = False
If .PrintComments <> xlPrintNoComments Then .PrintComments = xlPrintNoComments
' Etc...
End With
Application.ScreenUpdating = origScreenUpdating
Application.Calculation = origCalcMode
编辑:一些更新:
对于 Excel 2010 及更高版本,您可以使用“Application.PrintCommunication”属性,而对于 Excel 2007 及更低版本,您可以使用“ExecuteExcel4Macro”。更多详情请参见Migrating Excel 4 Macros to VBA .
对于 Excel 2007 及更低版本,另一个有趣的技巧是暂时将打印机驱动程序分配给“Microsoft XPS Document Writer”,然后将其设置回来。打印速度可提高3倍。请参阅:Slow Excel PageSetup Methods .
希望这有帮助...
关于vba - 在 Excel 中打印速度更快,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/230382/