在 Excel 中打印速度更快

编程入门 行业动态 更新时间:2024-10-23 05:37:43
本文介绍了在 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

一些更新:

  • 对于 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 中打印速度更快

    本文发布于:2023-06-01 10:28:38,感谢您对本站的认可!
    本文链接:https://www.elefans.com/category/jswz/34/412972.html
    版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
    本文标签:更快   打印速度   Excel

    发布评论

    评论列表 (有 0 条评论)
    草根站长

    >www.elefans.com

    编程频道|电子爱好者 - 技术资讯及电子产品介绍!