在 Excel 中打印速度更快 [英] Printing faster in Excel

查看:28
本文介绍了在 Excel 中打印速度更快的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Excel 的打印功能(使用 VBA)非常慢.我希望有人有办法加快打印速度(不使用 Excel 4 宏技巧).这是我现在的做法:

The print functionality of Excel (using VBA) is extremely slow. I'm hoping someone has a way of speeding the printing up (without using the Excel 4 Macro trick). Here's how I do it now:

Application.ScreenUpdating = False

With ActiveSheet.PageSetup

  -various setup statements which I've already minimized-

End With   
ActiveSheet.PrintOut

Application.ScreenUpdating = True

推荐答案

是的,设置 PageSetup 属性时非常慢.

Yes, the PageSetup properties are very slow when you set them.

您已经设置了 Application.ScreenUpdating = False,这很好,但在这种情况下同样(或更多)重要的一步是设置 Application.Calculation = xlCalculationManual.(最好保存这些设置,最后再恢复原状.)

You have already set Application.ScreenUpdating = False, which is good, but an equally (or more) important step in this case is to set Application.Calculation = xlCalculationManual. (It is best if you save these settings and then restore them to the original at the end.)

另外,每个PageSetup属性的propertyget都非常快,而只有property set才这么慢.因此,您应该测试新的属性设置以确保它与现有的属性值不同,以防止不必要的(且代价高昂的)调用.

Additionally, the property get for each PageSetup property is very fast, while it is only the property set that is so slow. Therefore, you should test the new property setting to make sure it isn't already the same as the existing property value in order to prevent an unnecessary (and expensive) call.

考虑到所有这些,您应该能够使用如下所示的代码:

With all this in mind, you should be able to use code that looks something like the following:

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

一些更新:

  1. 对于 Excel 2010 及更高版本,您可以使用Application.PrintCommunication"属性,而对于 Excel 2007 及更低版本,您可以使用ExecuteExcel4Macro".有关详细信息,请参阅 将 Excel 4 宏迁移到 VBA.

对于 Excel 2007 及以下版本,另一个有趣的技巧是将打印机驱动程序暂时分配给Microsoft XPS 文档编写器",然后将其重新设置.打印速度可提高 3 倍.请参阅:慢 Excel 页面设置方法.

For Excel 2007 and below, another interesting trick is to temporarily assign the printer driver to the 'Microsoft XPS Document Writer' and then set it back. Printing speed can improve by 3x. See: Slow Excel PageSetup Methods.

希望这有帮助...

这篇关于在 Excel 中打印速度更快的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆