
我需要列印 20 個單獨的 Word 文件。我不想打開每個並單擊列印。
我可以以某種方式一次列印所有內容嗎?
答案1
在 Windows 中,您可以選擇多個文件,右鍵單擊並選擇列印,它將列印您選擇的所有文件
然而,根據我的測試,它一次只能處理最多 15 個文件(我猜這是為了防止列印錯誤的資料夾而發生意外災難。)
答案2
我認為這不僅僅是一次性需求(否則您可以使用 Windows UI 選擇多個文檔,右鍵單擊並選擇列印)。
宏可以接受嗎?以下是從巨集開啟和列印 Word 文件所需的基本程式碼:
Sub PrintDocMacro()
Dim objWord As Object
Set objWord = CreateObject("Word.application") 'Start app
objWord.Documents.Open FileName:="c:\Temp\test.docx" 'Open doc
objWord.Visible = True
objWord.Application.PrintOut 'Print doc
objWord.ActiveDocument.Close savechanges:=True 'close & save doc
objWord.Application.Quit 'Close app
Set objWord = Nothing
End Sub
我們需要編寫一個循環來列印您想要的所有文件。如果您要列印的文檔是給定資料夾中的所有文檔,我們也可以這樣做。微軟有範例程式碼用於讀取目錄。
如果您出於某種原因想按計劃列印這些文件,我想您可以使包含巨集的文件使用「自動開啟」運行它,甚至在完成後關閉,然後安排透過任務排程器開啟啟用巨集的文件。
答案3
我意識到這是一個老問題,但我沒有看到我在這裡使用的答案。
您可以使用 Windows 資源管理器 shell 中的右鍵選項來列印多個文件。通常有 15 個文件的限制;然而,此限制可以在登錄中更改。以下是要修改為您所需限制的值:
HKCU\Software\Microsoft\Windows\CurrentVersion\Explorer
Name : MultipleInvokePromptMinimum
Type : DWORD
Default : 15 (decimal)
希望這可以幫助人們免去使用巨集的麻煩。
答案4
這是一個宏,可讓您指定一個資料夾,它將列印該資料夾內的所有 Word 文件,包括子資料夾。
Public optionCancel
Sub Print_word_files()
Dim path
Dim reminder As Integer
Dim oExtension As String
Dim Fso, oFolder, oSubfolder, oFile, queue As Collection
On Error Resume Next
path = " " //######################put files path here (ex: c:\users\myFiles) ################
If optionCancel = "yes" Then
optionCancel = "No"
Exit Sub
End If
reminder = MsgBox("Are you sure you want to print these files?", 4, "WARNING !!")
If reminder = 6 Then 'If Yes is clicked
Set Fso = CreateObject("Scripting.FileSystemObject")
Set queue = New Collection
queue.Add Fso.GetFolder(path) 'The path
Do While queue.Count > 0
Set oFolder = queue(1)
queue.Remove 1 'dequeue
'...insert any <<folder>> processing code here...
For Each oSubfolder In oFolder.subfolders
queue.Add oSubfolder 'enqueue
Next oSubfolder
For Each oFile In oFolder.Files
oExtension = Right(oFile, Len(oFile) - InStrRev(oFile, ".", -1)) 'gets the file extension
If oExtension = "docx" Or oExtension = "DOCX" Or oExtension = "doc" Or oExtension = "DOC" Or oExtension = "docm" Or oExtension = "DOCM" Or oExtension = "rtf" Or oExtension = "RTF" Then
Documents.Open FileName:=(oFile)
'-------------------The required starts here
ActiveDocument.PrintOut 'Prints document
ActiveDocument.Saved = True 'to prevent asking to save
ActiveDocument.Close 'Closes document
'-------------------The required ends here
End If
Next oFile
Loop
Else
MsgBox ("Operation cancelled!!")
End If
End Sub