Direkt zum Inhalt

Wie drucke ich Anhänge automatisch, wenn E-Mails in Outlook ankommen?

Dieses Tutorial zeigt eine Methode zum Kombinieren eines VBA-Skripts und einer Outlook-Regel, damit Sie Anhänge bestimmter E-Mails automatisch drucken können, wenn sie in Outlook ankommen.


Anhänge automatisch drucken, wenn bestimmte E-Mails eintreffen

Angenommen, Sie möchten Anhänge eingehender E-Mails von einem bestimmten Absender automatisch drucken. Sie können wie folgt vorgehen, um dies zu erreichen.

Schritt 1: Erstellen Sie ein Skript in Outlook

Zunächst müssen Sie ein VBA-Skript in Outlook erstellen.

1. Starten Sie Outlook und drücken Sie die Taste Andere + F11 Tasten gleichzeitig zum Öffnen der Microsoft Visual Basic für Applikationen Fenster.

2. In dem Microsoft Visual Basic für Applikationen Fenster, doppelklicken Sie auf Project1 > Microsoft Outlook-Objekte > DieseOutlookSession öffnen Diese Outlook-Sitzung (Code) Fenster, und kopieren Sie dann den folgenden Code in dieses Codefenster.

VBA-Code 1: Automatisches Drucken von Anhängen (alle Arten von Anhängen), wenn E-Mails eintreffen

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

Hinweis: Dieser Code unterstützt das Drucken aller Arten von Anhängen, die in E-Mails empfangen werden. Wenn Sie nur den angegebenen Anhangstyp drucken möchten, z. B. PDF-Dateien, wenden Sie bitte den folgenden VBA-Code an.

VBA-Code 2: Automatisches Drucken der angegebenen Art von Anhängen, wenn E-Mails eintreffen

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

Notizen:

1. Bevor Sie diesen VBA-Code anwenden, um nur die PDF-Datei in den eingehenden E-Mails zu drucken, müssen Sie ihn zuerst herunterladen und installieren Adobe Acrobat Reader und stellen Sie es als Standard-PDF-Reader auf Ihrem Computer ein.
2. In der Zeile Fall "pdf", Bitte austauschen "pdf" an die Dateierweiterung, die Sie drucken möchten.

3. Fahren Sie fort und klicken Sie Tools > Referenzen. Beim Auftauchen Referenzen – Projekt1 Wählen Sie im Dialogfeld Microsoft Scripting-Laufzeit Feld, und klicken Sie dann auf OK .

4. Speichern Sie den Code und drücken Sie die Taste Andere + Q Tasten zum Schließen der Microsoft Visual Basic für Applikationen Fenster.

Hinweis: Bitte stellen Sie sicher, dass die Aktivieren Sie alle Makros Option in Ihrem Outlook aktiviert ist. Sie können diese Option überprüfen, indem Sie die unten gezeigten Schritte ausführen.

Schritt 2: Erstellen Sie eine Regel zur Verwendung des Skripts

Nachdem Sie das VBA-Skript in Outlook hinzugefügt haben, müssen Sie eine Regel erstellen, um das Skript basierend auf bestimmten Bedingungen zu verwenden.

1. Gehen Sie zur Registerkarte Startseite, klicken Sie auf Regeln > Regeln und Warnungen verwalten.

2. In dem Regeln und Warnungen Klicken Sie im Dialogfeld auf die Schaltfläche Neue Regel Schaltfläche, um eine Regel zu erstellen.

Tipps: Wenn Sie mehrere E-Mail-Konten zu Ihrem Outlook hinzugefügt haben, geben Sie bitte ein Konto in der an Wenden Sie Änderungen auf diesen Ordner an Dropdown-Liste, wo Sie die Regel anwenden möchten. Andernfalls wird es auf den Posteingang des aktuell ausgewählten E-Mail-Kontos angewendet.

3. Im ersten Regel-Assistent Dialogfeld auswählen Übernehmen Sie Regeln für Nachrichten, die ich erhalte der Schritt 1 Box, und klicken Sie dann auf Weiter.

4. In dieser Sekunde Regel-Assistent Dialogfeld müssen Sie:

4.1) Geben Sie eine oder mehrere Bedingungen in der an Schritt 1 Box nach Ihren Bedürfnissen;
In diesem Fall möchte ich nur die Anhänge in eingehenden E-Mails von einem bestimmten Absender drucken. Hier überprüfe ich die von Menschen oder öffentlichen Gruppen Box.
4.2) Klicken Sie auf den unterstrichenen Wert in der Schritt 2 Feld zum Bearbeiten der Bedingung;
4.3) Klicken Sie auf Weiter. Screenshot:

5. Im dritten Regel-Assistent Dialogfeld müssen Sie wie folgt konfigurieren.

5.1) In der Schritt 1: Abschnitt Aktion(en) auswählen, Überprüf den Führen Sie ein Skript aus Box;
5.2) In der Schritt 2 Klicken Sie im Abschnitt auf den unterstrichenen Text „ein Skript“;
5.3) In der Öffnung Wählen Sie Skript Klicken Sie im Dialogfeld auf den Namen des VBA-Codes, den Sie oben hinzugefügt haben, und klicken Sie dann auf OK;
5.4) Klicken Sie auf Weiter Taste. Siehe Screenshot:

Tipps: Wenn das “Führen Sie ein Skript aus”-Option fehlt in Ihrer Regel-Assistent, können Sie es anzeigen, indem Sie der in diesem Artikel beschriebenen Methode folgen: Stellen Sie die fehlende Option „Skript ausführen“ in der Outlook-Regel wieder her.

6. Dann noch eine Regel-Assistent erscheint und fragt nach Ausnahmen. Sie können die Ausnahmen bei Bedarf auswählen, andernfalls klicken Sie auf Weiter Schaltfläche ohne Auswahl。

7. Im letzten Regel-Assistent, müssen Sie einen Namen für die Regel angeben und dann auf klicken Endziel .

8. Dann kehrt es zum zurück Regeln und Warnungen Dialogfeld können Sie die von Ihnen erstellte Regel darin aufgelistet sehen, klicken Sie auf die OK Schaltfläche, um die gesamten Einstellungen zu beenden.

Wenn von nun an eine E-Mail von der angegebenen Person eingeht, werden die angehängten Dateien automatisch gedruckt.


In Verbindung stehende Artikel

Drucken Sie Anhänge nur von einer E-Mail oder ausgewählten E-Mails in Outlook
In Outlook können Sie die E-Mails drucken, aber haben Sie die Anhänge nur von einer E-Mail oder ausgewählten E-Mails in Outlook gedruckt? Dieser Artikel stellt die Tricks zur Lösung dieser Aufgabe vor.

Drucken Sie nur den Nachrichtenkopf einer E-Mail in Outlook
Beim Drucken einer E-Mail in Outlook werden sowohl der Nachrichtenkopf als auch der Nachrichtentext in der E-Mail gedruckt. In einigen Sonderfällen müssen Sie jedoch möglicherweise nur den Nachrichtenkopf mit Betreff, Absender, Empfänger usw. ausdrucken. In diesem Artikel werden zwei Lösungen dafür vorgestellt.

Drucken Sie einen Kalender in einem bestimmten/benutzerdefinierten Datumsbereich in Outlook
Normalerweise wird beim Drucken eines Kalenders in der Monatsansicht in Outlook automatisch der Monat ausgewählt, der das aktuell ausgewählte Datum enthält. Möglicherweise müssen Sie den Kalender jedoch innerhalb eines benutzerdefinierten Datumsbereichs drucken, z. B. 3 Monate, ein halbes Jahr usw. In diesem Artikel wird die Lösung für Sie vorgestellt.

Drucken Sie einen Kontakt mit Bild in Outlook
Normalerweise wird das Bild eines Kontakts beim Drucken des Kontakts in Outlook nicht ausgedruckt. Aber manchmal ist es beeindruckender, einen Kontakt mit seinem Bild zu drucken. In diesem Artikel werden einige Problemumgehungen vorgestellt, um dies zu erreichen.

Drucken Sie eine Auswahl einer E-Mail in Outlook
Was würden Sie tun, wenn Sie eine E-Mail-Nachricht erhalten und feststellen würden, dass eine Auswahl des E-Mail-Inhalts ausgedruckt werden muss, anstatt die gesamte Nachricht zu drucken? Tatsächlich kann Outlook Ihnen dabei helfen, diesen Vorgang mithilfe von Internetbrowsern wie Firefox und Internet Explorer zu erreichen. Hier nehme ich zum Beispiel die Internetbrowser. Bitte schauen Sie sich die folgenden Tutorials an.

Weitere Artikel zum Thema "Drucken in Outlook"...


Beste Office-Produktivitätstools

Kutools for Outlook - Über 100 leistungsstarke Funktionen zur Optimierung Ihres Outlooks

🤖 KI-Mail-Assistent: Sofortige Profi-E-Mails mit KI-Magie – geniale Antworten mit einem Klick, perfekter Ton, mehrsprachige Beherrschung. Verwandeln Sie den E-Mail-Versand mühelos! ...

📧 E-Mail Automation: Abwesenheit (verfügbar für POP und IMAP)  /  Planen Sie das Senden von E-Mails  /  Automatisches CC/BCC nach Regeln beim E-Mail-Versand  /  Automatische Weiterleitung (erweiterte Regeln)   /  Begrüßung automatisch hinzufügen   /  Teilen Sie E-Mails mit mehreren Empfängern automatisch in einzelne Nachrichten auf ...

📨 E-Mail-Management: E-Mails einfach abrufen  /  Blockieren Sie betrügerische E-Mails nach Betreff und anderen  /  Doppelte E-Mails löschen  /  Erweiterte Suche  /  Ordner konsolidieren ...

📁 Anhänge ProBatch speichern  /  Stapeltrennung  /  Stapelkomprimierung  /  Automatisches Speichern   /  Automatische Trennung  /  Automatische Komprimierung ...

???? Schnittstellenmagie: 😊Mehr hübsche und coole Emojis   /  Steigern Sie Ihre Outlook-Produktivität mit Registerkartenansichten  /  Ausblick minimieren statt schließen ...

👍 Wunder mit einem Klick: Allen mit eingehenden Anhängen antworten  /   Anti-Phishing-E-Mails  /  🕘Zeitzone des Absenders anzeigen ...

👩🏼‍🤝‍👩🏻 Kontakte und Kalender: Fügen Sie Kontakte aus ausgewählten E-Mails im Stapel hinzu  /  Teilen Sie eine Kontaktgruppe in einzelne Gruppen auf  /  Geburtstagserinnerungen entfernen ...

Auf über 100 Eigenschaften Warten Sie auf Ihre Erkundung! Klicken Sie hier, um mehr zu erfahren.

 

 

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