Przejdź do głównej zawartości

Jak automatycznie drukować załączniki po nadejściu wiadomości e-mail w programie Outlook?

W tym samouczku przedstawiono metodę łączenia skryptu VBA i reguły programu Outlook, aby pomóc w automatycznym drukowaniu załączników niektórych wiadomości e-mail po ich przybyciu do programu Outlook.


Automatycznie drukuj załączniki po otrzymaniu określonych wiadomości e-mail

Przypuśćmy, że chcesz automatycznie drukować załączniki przychodzących wiadomości e-mail od określonego nadawcy. Aby to zrobić, możesz wykonać następujące czynności.

Krok 1: Utwórz skrypt w Outlooku

Po pierwsze, musisz utworzyć skrypt VBA w Outlooku.

1. Uruchom program Outlook, naciśnij inny + F11 klawisze jednocześnie, aby otworzyć Microsoft Visual Basic for Applications okno.

2. w Microsoft Visual Basic for Applications okno, kliknij dwukrotnie Project1 > Obiekty programu Microsoft Outlook > Ta sesja programu Outlook otworzyć ThisOutlookSession (kod) okno, a następnie skopiuj następujący kod do tego okna kodu.

Kod VBA 1: Automatycznie drukuj załączniki (wszystkie rodzaje załączników) po nadejściu wiadomości e-mail

Sub AttachementAutoPrint(Item As Outlook.MailItem)
'Updated by Extendoffice 20230223
  Dim xFS As FileSystemObject
  Dim xTempFolder As String
  Dim xAtt As Attachment
  Dim xShell As Object
  Dim xFolder As Object, xFolderItem As Object
  Dim xFileName As String
  On Error GoTo xError
  If Item.Attachments.Count = 0 Then Exit Sub
  Set xFS = New FileSystemObject
  xTempFolder = xFS.GetSpecialFolder(TemporaryFolder)
  xTempFolder = xTempFolder & "\ATMP" & Format(Item.ReceivedTime, "yyyymmddhhmmss")
  If Not xFS.FolderExists(xTempFolder) Then
    MkDir (xTempFolder)
  End If
  Set xShell = CreateObject("Shell.Application")
  Set xFolder = xShell.NameSpace(0)
  For Each xAtt In Item.Attachments
    If IsEmbeddedAttachment(xAtt) = False Then
      xFileName = xTempFolder & "\" & xAtt.FileName
      xAtt.SaveAsFile (xFileName)
      Set xFolderItem = xFolder.ParseName(xFileName)
      xFolderItem.InvokeVerbEx ("print")
    End If
  Next xAtt
  Set xFS = Nothing
  Set xFolder = Nothing
  Set xFolderItem = Nothing
  Set xShell = Nothing
xError:
  If Err <> 0 Then
    MsgBox Err.Number & " - " & Err.Description, , "Kutools for Outlook"
    Err.Clear
  End If
Exit Sub
End Sub

Function IsEmbeddedAttachment(Attach As Attachment)
Dim xItem As MailItem
Dim xCid As String
Dim xID As String
Dim xHtml As String
On Error Resume Next
IsEmbeddedAttachment = False
Set xItem = Attach.Parent
If xItem.BodyFormat <> olFormatHTML Then Exit Function
xCid = ""
xCid = Attach.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F")
If xCid <> "" Then
    xHtml = xItem.HTMLBody
    xID = "cid:" & xCid
    If InStr(xHtml, xID) > 0 Then
        IsEmbeddedAttachment = True
    End If
End If
End Function

Uwaga: Ten kod obsługuje drukowanie wszystkich typów załączników otrzymywanych w wiadomościach e-mail. Jeśli chcesz wydrukować tylko określony typ załącznika, taki jak pliki pdf, zastosuj następujący kod VBA.

Kod VBA 2: Automatycznie drukuj określony typ załączników po nadejściu wiadomości e-mail

Sub AttachementAutoPrint(Item As Outlook.MailItem)
'Updated by Extendoffice 20230223
  Dim xFS As FileSystemObject
  Dim xTempFolder As String
  Dim xAtt As Attachment
  Dim xShell As Object
  Dim xFolder As Object, xFolderItem As Object
  Dim xFileType As String, xFileName As String
  On Error GoTo xError
  If Item.Attachments.Count = 0 Then Exit Sub
  Set xFS = New FileSystemObject
  xTempFolder = xFS.GetSpecialFolder(TemporaryFolder)
  xTempFolder = xTempFolder & "\ATMP" & Format(Item.ReceivedTime, "yyyymmddhhmmss")
  If Not xFS.FolderExists(xTempFolder) Then
    MkDir (xTempFolder)
  End If
  Set xShell = CreateObject("Shell.Application")
  Set xFolder = xShell.NameSpace(0)
  For Each xAtt In Item.Attachments
    If IsEmbeddedAttachment(xAtt) = False Then
      xFileName = xAtt.FileName
      xFileType = LCase$(Right$(xFileName, VBA.Len(xFileName) - VBA.InStrRev(xFileName, ".")))
      xFileName = xTempFolder & "\" & xFileName
      Select Case xFileType
        Case "pdf"   'change "pdf" to the file extension you want to print
          xAtt.SaveAsFile (xFileName)
          Set xFolderItem = xFolder.ParseName(xFileName)
          xFolderItem.InvokeVerbEx ("print")
      End Select
    End If
  Next xAtt
  Set xFS = Nothing
  Set xFolder = Nothing
  Set xFolderItem = Nothing
  Set xShell = Nothing
xError:
  If Err <> 0 Then
    MsgBox Err.Number & " - " & Err.Description, , "Kutools for Outlook"
    Err.Clear
  End If
  Exit Sub
End Sub

Function IsEmbeddedAttachment(Attach As Attachment)
Dim xItem As MailItem
Dim xCid As String
Dim xID As String
Dim xHtml As String
On Error Resume Next
IsEmbeddedAttachment = False
Set xItem = Attach.Parent
If xItem.BodyFormat <> olFormatHTML Then Exit Function
xCid = ""
xCid = Attach.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F")
If xCid <> "" Then
    xHtml = xItem.HTMLBody
    xID = "cid:" & xCid
    If InStr(xHtml, xID) > 0 Then
        IsEmbeddedAttachment = True
    End If
End If
End Function

Uwagi:

1. Przed zastosowaniem tego kodu VBA do drukowania tylko pliku pdf w przychodzących wiadomościach e-mail, najpierw musisz pobrać i zainstalować Adobe Acrobat Reader i ustaw go jako domyślny czytnik PDF na swoim komputerze.
2. W kolejce Sprawa "pdf", proszę zmień "pdf" do rozszerzenia pliku, który chcesz wydrukować.

3. Śmiało i kliknij Tools > Referencje. W wyskakującym okienku Referencje – Projekt1 w oknie dialogowym, sprawdź Środowisko wykonawcze skryptów firmy Microsoft Microsoft a następnie kliknij OK przycisk.

4. Zapisz kod i naciśnij inny + Q klucze do zamknięcia Microsoft Visual Basic for Applications okno.

Uwaga: Upewnij się, że Włącz wszystkie makra opcja jest włączona w Twoim Outlooku. Możesz sprawdzić tę opcję, wykonując czynności przedstawione poniżej.

Krok 2: Zbuduj regułę do korzystania ze skryptu

Po dodaniu skryptu VBA w Outlooku musisz utworzyć regułę, aby używać skryptu na podstawie określonych warunków.

1. Przejdź do zakładki Strona główna, kliknij Zasady > Zarządzaj regułami i alertami.

2. w Reguły i alerty okno dialogowe, kliknij przycisk Nowa zasada przycisk, aby utworzyć regułę.

Porady: Jeśli dodałeś wiele kont e-mail do swojego Outlooka, określ konto w Zastosuj zmiany w tym folderze listę rozwijaną, w której chcesz zastosować regułę. W przeciwnym razie zostanie zastosowany do skrzynki odbiorczej aktualnie wybranego konta e-mail.

3. W pierwszym Kreator reguł okno dialogowe, wybierz Zastosuj regułę do otrzymywanych wiadomości Krok 1 , a następnie kliknij Dalej.

4. W sekundę Kreator reguł w oknie dialogowym, musisz:

4.1) Określ jeden lub więcej warunków w Krok 1 pudełko według Twoich potrzeb;
W takim przypadku chcę drukować tylko załączniki w wiadomościach przychodzących od określonego nadawcy. Tutaj sprawdzam od osób lub grupy publicznej pudełko.
4.2) Kliknij podkreśloną wartość w Krok 2 pole do edycji warunku;
4.3) Kliknij Dalej. Zobacz zrzut ekranu:

5. W trzecim Kreator reguł W oknie dialogowym należy skonfigurować w następujący sposób.

5.1) W Krok 1: Wybierz sekcję działań, Sprawdź uruchom skrypt pudełko;
5.2) W Krok 2 sekcji, kliknij podkreślony tekst „skrypt”;
5.3) W otwarciu Wybierz Skrypt w oknie dialogowym kliknij nazwę kodu VBA, który dodałeś powyżej, a następnie kliknij OK;
5.4) Kliknij Następna przycisk. Zobacz zrzut ekranu:

Porady: Jeśli "uruchom skrypt” brakuje opcji w twoim Kreator reguł, możesz go wyświetlić, postępując zgodnie z metodą opisaną w tym artykule: przywrócić brakującą opcję Uruchom skrypt w regule programu Outlook.

6. Potem kolejny Kreator reguł wyskakuje pytanie o wyjątki. W razie potrzeby możesz wybrać wyjątki, w przeciwnym razie kliknij Następna przycisk bez żadnych wyborów。

7. W ostatnim Kreator reguł, musisz podać nazwę reguły, a następnie kliknąć koniec przycisk.

8. Następnie wraca do Reguły i alerty w oknie dialogowym, możesz zobaczyć utworzoną regułę wymienioną w środku, kliknij OK aby zakończyć wszystkie ustawienia.

Od tej chwili, po otrzymaniu wiadomości e-mail od określonej osoby, załączone pliki zostaną wydrukowane automatycznie.


Powiązane artykuły

Drukuj tylko załączniki z jednego e-maila lub wybranych wiadomości e-mail w programie Outlook
W Outlooku możesz drukować wiadomości e-mail, ale czy wydrukowałeś załączniki tylko z jednego e-maila lub wybranych wiadomości e-mail w Outlooku? Ten artykuł przedstawia triki dotyczące rozwiązania tego zadania.

Drukuj tylko nagłówek wiadomości e-mail w programie Outlook
Podczas drukowania wiadomości e-mail w programie Outlook wydrukuje zarówno nagłówek wiadomości, jak i treść wiadomości w wiadomości e-mail. Jednak w niektórych szczególnych przypadkach może być konieczne wydrukowanie nagłówka wiadomości z tematem, nadawcą, odbiorcami itp. W tym artykule przedstawimy dwa rozwiązania, aby to zrobić.

Wydrukuj kalendarz w określonym/niestandardowym zakresie dat w programie Outlook
Zwykle podczas drukowania kalendarza w widoku miesiąca w Outlooku automatycznie wybierze miesiąc zawierający aktualnie wybraną datę. Ale może być konieczne wydrukowanie kalendarza w niestandardowym zakresie dat, takim jak 3 miesiące, pół roku itp. W tym artykule przedstawimy rozwiązanie dla Ciebie.

Wydrukuj kontakt ze zdjęciem w programie Outlook
Zwykle zdjęcie kontaktu nie zostanie wydrukowane podczas drukowania kontaktu w programie Outlook. Ale czasami wydrukowanie kontaktu z jego zdjęciem będzie bardziej imponujące. W tym artykule przedstawimy kilka obejść, aby to zrobić.

Wydrukuj wybrane wiadomości e-mail w programie Outlook
Jeśli otrzymałeś wiadomość e-mail i okazało się, że część treści wiadomości e-mail musi zostać wydrukowana zamiast drukować całą wiadomość, co byś zrobił? W rzeczywistości program Outlook może pomóc w wykonaniu tej operacji za pomocą przeglądarek internetowych, takich jak Firefox i Internet Explorer. W tym miejscu wezmę na przykład przeglądarki internetowe. Proszę spojrzeć na poniższe samouczki.

Więcej artykułów na temat „drukowania w programie Outlook”...


Najlepsze narzędzia biurowe

Kutools dla programu Outlook - Ponad 100 zaawansowanych funkcji, które usprawnią Twoje perspektywy

🤖 Asystent poczty AI: Natychmiastowe profesjonalne e-maile z magią AI — genialne odpowiedzi jednym kliknięciem, doskonały ton, biegła znajomość wielu języków. Zmień e-mailing bez wysiłku! ...

📧 Automatyzacja poczty e-mail: Poza biurem (dostępne dla POP i IMAP)  /  Zaplanuj wysyłanie wiadomości e-mail  /  Automatyczne CC/BCC według reguł podczas wysyłania wiadomości e-mail  /  Automatyczne przewijanie (Zasady zaawansowane)   /  Automatyczne dodawanie powitania   /  Automatycznie dziel wiadomości e-mail od wielu odbiorców na pojedyncze wiadomości ...

📨 Zarządzanie e-mail: Łatwe przywoływanie e-maili  /  Blokuj oszukańcze wiadomości e-mail według tematów i innych  /  Usuń zduplikowane wiadomości e-mail  /  Wiecej opcji  /  Konsoliduj foldery ...

📁 Załączniki ProZapisz zbiorczo  /  Odłącz partię  /  Kompresuj wsadowo  /  Automatyczne zapisywanie   /  Automatyczne odłączanie  /  Automatyczna kompresja ...

🌟 Magia interfejsu: 😊Więcej ładnych i fajnych emotikonów   /  Zwiększ produktywność programu Outlook dzięki widokom na kartach  /  Zminimalizuj program Outlook zamiast go zamykać ...

>> Cuda jednym kliknięciem: Odpowiedz wszystkim, dodając przychodzące załączniki  /   E-maile chroniące przed phishingiem  /  🕘Pokaż strefę czasową nadawcy ...

👩🏼‍🤝‍👩🏻 Kontakty i kalendarz: Grupowe dodawanie kontaktów z wybranych e-maili  /  Podziel grupę kontaktów na pojedyncze grupy  /  Usuń przypomnienia o urodzinach ...

O Cechy 100 Poczekaj na eksplorację! Kliknij tutaj, aby dowiedzieć się więcej.

 

 

Comments (22)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Kan deze script ook gemaakt worden voor het verzenden van emails, dat je dan automatisch de bijlage kan laten afdrukken ?
This comment was minimized by the moderator on the site
Hello, thank you very much for the scripts, very useful indeed!
What if we wanted to print all attachments in an email in Outlook 365 web instead? Are there ways to try this?
This comment was minimized by the moderator on the site
Hi is there a way to print the email body including sender details and subject line in the script please. I pretty much need email and attachment printed out please.
This comment was minimized by the moderator on the site
Hi Mani,

If you want to print an email body including sender details and subject line, I suggest you try the Advanced Print feature of Kutools for Outlook. It can help you solve the problem easily.
https://www.extendoffice.com/images/stories/comments/comment-picture-zxm/advanced-print.png?1696644946
This comment was minimized by the moderator on the site
First of all, thanks a lot for these useful VBA scripts!
My situation is as follows: I usually receive a number of emails with 2 pdf files each. One pdf file, let's call it example1.pdf, needs to be printed only once, but the second pdf file, let's call it example2.pdf, needs to be printed 3 times. The example2.pdf does not necessarily always have the same name, but there are only around 2-4 name variants, so if it were possible to tell the script to look out for a few keywords I think it would work. Is this possible?
Oh, and would it be possible to also tell the script to print the example1.pdf file as duplex?
Thanks for your help.
This comment was minimized by the moderator on the site
Hi There, thanks for publishing this

I have followed the instructions above and are running the script to print all attachments delivered.

we typically receive these in batches of 5-8 and when testing i am getting 4 out of 5 prints with one failing with error 75. All PDF's have different names and are on separate emails/ the attachements can be opened manually fine so i assume theres an issue when it tries to copy this to the temp directory. Do you have any idea how we can resolve this?
This comment was minimized by the moderator on the site
Same problem here. After a couple of emails received during a short time, it can print 3-4 pdf, but after the error 75 appear, nothing print in the same batch of mails.
This comment was minimized by the moderator on the site
Hi Gabriel,
After testing, we have reproduced the problem you encountered. the VBA scripts have been updated in the post. Please give them a try. Thanks for your feedback.
This comment was minimized by the moderator on the site
Love this script! How about if I get an email with multiple pdfs and want one copy of each. Currently when I get 3 pdf's attached, it prints the final one, 3 times, and the other 2 do not get printed. Thanks for any help!
This comment was minimized by the moderator on the site
Hi val,

Sorry for the inconvenience.
Which VBA code are you applying? VBA code 1 or VBA code 2? Do the three PDF attachments have the same name? And which Outlook version are you using?
I have tested the codes and they worked well in my case. I need to know more specific about your issue.
This comment was minimized by the moderator on the site
Is it possible to specify the printer that should be used (not the system default printer)?
I need to print 2 types of documents on 2 different printers....
Thanks for your help!
This comment was minimized by the moderator on the site
Hi Simon,
Thank you for your comment. After trying with various methods, I can't seem to get this to work. Sorry for the inconvenience.
This comment was minimized by the moderator on the site
Hello, kindly I need help, I can't integrate the script for printing pdf only.
I activated everything, the first script for generic printing works perfectly (or almost: printing pdf attachments once printed acrobat reader remains open in the background), but the specific script for pdf does not work. Thanks for posting the scripts and for any help.
Good day
This comment was minimized by the moderator on the site
Hi Marco041,
There was something wrong with the code and it has been updated. Please give it a try.
Note: we have no way to prevent Acrobat Reader from being opened because we need to use it to open the pdf document for the next print job.
Thank you for your feedback.
Sub AttachementAutoPrint(Item As Outlook.MailItem)
'Updated by Extendoffice 20220920
  Dim xFS As FileSystemObject
  Dim xTempFolder As String
  Dim xAtt As Attachment
  Dim xShell As Object
  Dim xFolder As Object, xFolderItem As Object
  Dim xFileType As String, xFileName As String
  On Error GoTo xError
  Set xFS = New FileSystemObject
  xTempFolder = xFS.GetSpecialFolder(TemporaryFolder)
  xTempFolder = xTempFolder & "\ATMP" & Format(Now, "yyyymmddhhmmss")
  MkDir (xTempFolder)
  'Set Item = Application.ActiveExplorer.Selection.Item(1)
  Set xShell = CreateObject("Shell.Application")
  Set xFolder = xShell.NameSpace(0)
  For Each xAtt In Item.Attachments
    xFileName = xAtt.FileName
    xFileType = LCase$(Right$(xFileName, VBA.Len(xFileName) - VBA.InStrRev(xFileName, ".")))
    xFileName = xTempFolder & "\" & xFileName
    xAtt.SaveAsFile (xFileName)
    Select Case xFileType
      Case "pdf"   'change "pdf" to the file extension you want to print
        Set xFolderItem = xFolder.ParseName(xFileName)
        xFolderItem.InvokeVerbEx ("print")
    End Select
  Next xAtt
'xFS.DeleteFolder (xTempFolder)
Set xFS = Nothing
Set xFolder = Nothing
Set xFolderItem = Nothing
Set xShell = Nothing
xError:
  If Err <> 0 Then
    MsgBox Err.Number & " - " & Err.Description, , "Kutools for Outlook"
    Err.Clear
  End If
Exit Sub
End Sub
This comment was minimized by the moderator on the site
Bonjour question pour vous j'ai fait les étapes pour cela mais dans les règle de message de mon outlook je ne voit pas que je peux utilisé un script
This comment was minimized by the moderator on the site
Hi STEPHANE CADORETTE,
If the “run a script” option is missing in your Rules Wizard, you can display it by following the method mentioned in this article: restore missing Run A Script pption in Outlook rule.
This comment was minimized by the moderator on the site
Bonjour moi j'ai un petit soucie lorsque j'ai fait et refait les étapes mais lorsque je créer ma règle je n'Ai pas l'option run a script.
This comment was minimized by the moderator on the site
Hi Stéphane,
If the “run a script” option is missing in your Rules Wizard, you can display it by following the method mentioned in this article: restore missing Run A Script pption in Outlook rule.
There are no comments posted here yet
Load More
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations