首页 > 解决方案 > 如何加快将选定单元格打印到 pdf 文件并将 xlsm 文件保存到共享设备?

问题描述

我刚刚在 VBA 中编写了 MS 宏脚本,它选择要打印到 pdf 文件的单元格并将 pdf 和 xlsm 文件保存在共享设备中(在这种情况下,我有 Raspberry Pi)。当我选择单元格 A1:X51 时,它会打印出来,但需要很长时间。我试过添加那几行代码:

Application.Calculation = xlCalculationManual
     Application.ScreenUpdating = False
     Application.DisplayStatusBar = False
     Application.EnableEvents = False
     Application.DisplayAlerts = False
     ActiveSheet.DisplayPageBreaks = False

但这些都没有帮助。我现在有一个问题:是否可以加快打印选定单元格并将 pdf 和 xlsm 文件保存到共享设备的速度?

提前致谢。

宏代码:

Sub SaveFile()
'
' Macro Macro
'

'
    ActiveSheet.PageSetup.PaperSize = xlPaperLegal
    ActiveSheet.PageSetup.PrintArea = Selection.Address
    ActiveSheet.ExportAsFixedFormat Type:=xlTypePDF, Filename:="\\raspberrypi\Home_share\File.pdf", _
         Quality:=xlQualityStandard, _
         IncludeDocProperties:=True, _
         IgnorePrintAreas:=False, _
         OpenAfterPublish:=True
    With ActiveSheet.PageSetup
        .LeftMargin = Application.InchesToPoints(0)
        .RightMargin = Application.InchesToPoints(0)
        .TopMargin = Application.InchesToPoints(0)
        .BottomMargin = Application.InchesToPoints(0)
        .HeaderMargin = Application.InchesToPoints(0)
        .FooterMargin = Application.InchesToPoints(0)
        .Orientation = xlLandscape
        .Zoom = False
        .FitToPagesWide = 1
        .FitToPagesTall = False
    End With
         Application.Calculation = xlCalculationManual
         Application.ScreenUpdating = False
         Application.DisplayStatusBar = False
         Application.EnableEvents = False
         Application.DisplayAlerts = False
         ActiveSheet.DisplayPageBreaks = False

         ActiveWorkbook.SaveAs "\\raspberrypi\Home_share\File-TV.xlsm"
         ActiveWorkbook.Close

End Sub

标签: excelvbaexport-to-pdf

解决方案


推荐阅读