Skip to content

Instantly share code, notes, and snippets.

@hylickipiotr
Last active May 31, 2021 14:47
Show Gist options
  • Select an option

  • Save hylickipiotr/865ef127bdd4534606d9ca5c3b68c7a7 to your computer and use it in GitHub Desktop.

Select an option

Save hylickipiotr/865ef127bdd4534606d9ca5c3b68c7a7 to your computer and use it in GitHub Desktop.
Print multiple MS Word documents

Instrukcja

  1. Utwórz nowy folder, w którym będą się znajdować tylko pliki MS Word, które chcesz wydrukować
  2. Utwórz nowy plik MS Word
  3. Otwórz okno Visual Basic
  4. Z górej wstążki wybierz Insert -> Module
  5. Przeklej kod ponizej do okna VBA
  6. Uruchom skrypt
Sub BatchPrintWordDocuments()
Dim objWordApplication As New Word.Application
Dim strFile As String
Dim strFolder As String
On Error GoTo Err
strFolder = InputBox("Podaj ścieżkę do folderu", "Ścieżka folderu")
If Not Right(strFolder, 1) = "\" Then
strFolder = strFolder & "\"
End If
strCopiesCount = InputBox("Ilość kopii", "Ilość kopii", "1")
strFile = Dir(strFolder & "*.doc*", vbNormal)
copiesCount = Int(strCopiesCount)
While strFile <> ""
With objWordApplication
.Documents.Open (strFolder & strFile)
.ActiveDocument.PrintOut Copies:=copiesCount, ManualDuplexPrint:=False
.ActiveDocument.Close
End With
strFile = Dir()
Wend
Set objWordApplication = Nothing
MsgBox "Wszystkie pliki zostały przekazane do druku. Możesz już bezpiecznie zamknąć Word'a."
Exit Sub
Err:
MsgBox "Coś poszło nie tak. Spróbuj ponownie"
End Sub
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment