我现在正在打印一个装满 xlsx 文件的文件夹。我希望优化并使过程更快 - 将 20 页发送到打印机大约需要 40 秒,即来自 20 个不同文件的一页。
我可以先将这些页面中的每一个发送到 PDF 文件,然后将该 PDF 文件发送到打印机一次(然后我可以在页面的两面打印 - 这太棒了)
我更愿意这样做,因为当应用程序完成时,它会一次打印多达 300 页。所以我认为你可以看到能够使用双方的优势,只需将一个 pdf 文件发送到打印机。
任何帮助都会很棒,
当前代码:
Sub Print_Long_Sections(ByVal LongFolderPath As String)
' ####################################################################################
' # INTRO
'-------------------------------------------------------------------------------------
' Purpose
' This procedure assist the user to print all the long section files in the
' folder that they saved the files to. This saves the need to open all the files
'
'
'
' ####################################################################################
' # DECLAIRATIONS
'-------------------------------------------------------------------------------------
' OBJECTS
Dim LongFolder As Folder
Dim LongFile As File
Dim OpenLong As Workbook
Dim FileSystemObj As New FileSystemObject
'-------------------------------------------------------------------------------------
' VARIABLES
Dim iLoopVar As Long
Dim DefaultPrinter As String
' ####################################################################################
' # PROCEDURE CODE
'-------------------------------------------------------------------------------------
' optimise speed
Application.ScreenUpdating = False
'-------------------------------------------------------------------------------------
' Select the Printer
DefaultPrinter = Application.ActivePrinter
MsgBox "Select your printer"
Application.Dialogs(xlDialogPrinterSetup).Show
'-------------------------------------------------------------------------------------
' Print the Files in the Folder:
Set LongFolder = FileSystemObj.GetFolder(LongFolderPath) '// set the folder object to the user specified folder
For Each LongFile In LongFolder.Files '// loop through all the files in the folder
If FileSystemObj.GetExtensionName(LongFile.Path) = "xlsx" Then '// check file is an xlsx file,
If InStr(1, LongFile.Name, "PipeLongSec") > 0 Then '// check file is a long section
Set OpenLong = Workbooks.Open(LongFile.Path) '// open the file
OpenLong.Sheets(1).PrintOut '// send file to default printer
OpenLong.Close '// close the file
End If
End If
Next
'-------------------------------------------------------------------------------------
' Re-Set Printer to Previous Settings
Application.ActivePrinter = DefaultPrinter
'-------------------------------------------------------------------------------------
' END PROCEDURE
Application.ScreenUpdating = True
Set OpenLong = Nothing
Set LongFolder = Nothing
Set LongFile = Nothing
Set FileSystemObj = Nothing
End Sub
问候,
乔