Salt la conținutul principal

Cum să imprimați automat atașamentele când sosesc e-mailurile în Outlook?

Acest tutorial demonstrează o metodă de a combina un script VBA și o regulă Outlook pentru a vă ajuta să imprimați automat atașamentele anumitor e-mailuri atunci când ajung în Outlook.


Imprimați automat atașamentele când sosesc anumite e-mailuri

Să presupunem că doriți să imprimați automat atașamentele e-mailurilor primite de la un anumit expeditor. Puteți face după cum urmează pentru a finaliza.

Pasul 1: Creați un script în Outlook

În primul rând, trebuie să creați un script VBA în Outlook.

1. Lansați Outlook, apăsați butonul Alt + F11 tastele simultan pentru a deschide Microsoft Visual Basic pentru aplicații fereastră.

2. În Microsoft Visual Basic pentru aplicații fereastra, faceți dublu clic pe Project1 > Obiecte Microsoft Outlook > Această sesiune Outlook pentru a deschide ThisOutlookSession (Cod) fereastră, apoi copiați următorul cod în această fereastră de cod.

Cod VBA 1: imprimați automat atașamente (toate tipurile de atașamente) când sosesc e-mailurile

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

Notă: Acest cod acceptă imprimarea tuturor tipurilor de atașamente primite în e-mailuri. Dacă doriți să imprimați numai tipul specificat de atașament, cum ar fi fișierele pdf, vă rugăm să aplicați următorul cod VBA.

Cod VBA 2: imprimați automat tipul specificat de atașamente atunci când sosesc e-mailurile

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

notițe:

1. Înainte de a aplica acest cod VBA pentru a tipări numai fișierul pdf din e-mailurile primite, mai întâi trebuie să descărcați și să instalați Adobe Acrobat Reader și setați-l ca cititor pdf implicit pe computer.
2. În linie Cazul „pdf”, te rog schimba "pdf" la extensia de fișier pe care doriți să o imprimați.

3. Continuați și faceți clic Instrumente > Referințe. În pop-up Referințe – Proiect1 caseta de dialog, verificați Runtime Microsoft Scripting , apoi faceți clic pe OK butonul.

4. Salvați codul și apăsați tasta Alt + Q tastele pentru a închide Microsoft Visual Basic pentru aplicații fereastră.

Notă: Vă rugăm să vă asigurați că Activați toate macrocomenzile opțiunea este activată în Outlook. Puteți verifica această opțiune urmând pașii de mai jos.

Pasul 2: Creați o regulă pentru a utiliza scriptul

După ce adăugați scriptul VBA în Outlook, trebuie să creați o regulă pentru a utiliza scriptul pe baza anumitor condiții.

1. Accesați fila Acasă, faceți clic Reguli > Gestionați regulile și alertele.

2. În Reguli și alerte , faceți clic pe Noua regulă pentru a crea o regulă.

Sfat: Dacă ați adăugat mai multe conturi de e-mail în Outlook, vă rugăm să specificați un cont în Aplicați modificări la acest folder lista derulantă în care doriți să aplicați regula. În caz contrar, va fi aplicat în căsuța de e-mail a contului de e-mail selectat în prezent.

3. În prima Expertul pentru reguli fereastră de dialog, selectați Aplică regulă pe mesajele pe care le primesc în Etapa 1 , apoi faceți clic pe Următorul.

4. În al doilea Expertul pentru reguli casetă de dialog, trebuie să:

4.1) Specificați una sau mai multe condiții în Etapa 1 cutie conform nevoilor tale;
În acest caz, vreau să printez numai atașamentele din e-mailurile primite de la un expeditor specificat. Aici, verific de la oameni sau grup public cutie.
4.2) Faceți clic pe valoarea subliniată din Etapa 2 caseta pentru a edita condiția;
4.3) Faceți clic pe Următorul. Vedeți captura de ecran:

5. În al treilea Expertul pentru reguli casetă de dialog, trebuie să configurați după cum urmează.

5.1) În Pasul 1: Selectați secțiunea acțiuni, verifică rulați un script cutie;
5.2) În Etapa 2 secțiunea, faceți clic pe textul subliniat „un script”;
5.3) În deschidere Selectați Script caseta de dialog, faceți clic pe numele codului VBA adăugat mai sus, apoi faceți clic O.K;
5.4) Faceți clic pe Pagina Următoare → buton. Vedeți captura de ecran:

Sfat: Dacă "rulați un script” lipsește opțiunea din dvs Expertul pentru reguli, îl puteți afișa urmând metoda menționată în acest articol: restaurați lipsa Run A Script pption în regula Outlook.

6. Apoi alta Expertul pentru reguli apare cerând excepții. Puteți selecta excepțiile dacă este necesar, în caz contrar, faceți clic pe Pagina Următoare → buton fără nicio selecție。

7. În ultimul Expertul pentru reguli, trebuie să specificați un nume pentru regulă, apoi să faceți clic pe finalizarea butonul.

8. Apoi revine la Reguli și alerte caseta de dialog, puteți vedea regula pe care ați creat-o listată în interior, faceți clic pe OK pentru a finaliza toate setările.

De acum înainte, când se primește un e-mail de la persoana specificată, fișierele atașate vor fi tipărite automat.


Articole pe aceeași temă

Imprimați doar atașamentele dintr-un e-mail sau dintr-un e-mail selectat din Outlook
În Outlook, puteți imprima e-mailurile, dar ați imprimat atașamentele doar dintr-un e-mail sau e-mailuri selectate în Outlook? Acest articol prezintă trucurile pentru rezolvarea acestei sarcini.

Imprimați numai antetul mesajului unui e-mail în Outlook
Când imprimați un e-mail în Outlook, acesta va imprima atât antetul mesajului, cât și corpul mesajului în e-mail. Cu toate acestea, în unele cazuri speciale, este posibil să fie nevoie doar să tipăriți antetul mesajului cu subiectul, expeditorul, destinatarii etc. Acest articol va introduce două soluții pentru a face acest lucru.

Imprimați un calendar într-un interval de date specificat/personalizat în Outlook
În mod normal, atunci când imprimați un calendar în vizualizarea Lună în Outlook, acesta va selecta automat luna care conține data selectată curent. Dar, poate fi necesar să tipăriți calendarul într-un interval de date personalizat, cum ar fi 3 luni, jumătate de an etc. Acest articol vă va prezenta soluția.

Imprimați un contact cu imagine în Outlook
În mod normal, imaginea unui contact nu va fi tipărită la imprimarea contactului în Outlook. Dar, uneori, va fi mai impresionant să imprimați un contact cu imaginea sa. Acest articol va introduce câteva soluții pentru a o face.

Imprimați o selecție a unui e-mail în Outlook
Dacă ați primit un mesaj de e-mail și ați descoperit că există o selecție a conținutului de e-mail care trebuie imprimat în loc să imprimați întregul mesaj, ce ați face? De fapt, Outlook vă poate ajuta să realizați această operațiune cu ajutorul browserelor de internet, cum ar fi Firefox și Internet Explorer. Aici voi lua de exemplu browserele de Internet. Vă rugăm să consultați următoarele tutoriale.

Mai multe articole despre „imprimarea în Outlook”...


Cele mai bune instrumente de productivitate de birou

Kutools pentru Outlook - Peste 100 de funcții puternice pentru a vă supraalimenta Outlook

🤖 AI Mail Assistant: E-mailuri profesionale instantanee cu magie AI--un singur clic pentru răspunsuri geniale, ton perfect, stăpânire în mai multe limbi. Transformați e-mailurile fără efort! ...

📧 Automatizare e-mail: În afara biroului (disponibil pentru POP și IMAP)  /  Programați trimiterea de e-mailuri  /  CC/BCC automat după reguli la trimiterea e-mailului  /  Redirecționare automată (Reguli avansate)   /  Adăugare automată felicitare   /  Împărțiți automat e-mailurile cu mai mulți destinatari în mesaje individuale ...

📨 Managementul e-mail: Amintește-ți cu ușurință e-mailurile  /  Blocați e-mailurile înșelătorii de către subiecți și alții  /  Ștergeți e-mailurile duplicate  /  Cautare Avansata  /  Consolidați foldere ...

📁 Atașamente ProSalvați în serie  /  Detașare lot  /  Compresă în loturi  /  Salvare automata   /  Detașare automată  /  Comprimare automată ...

🌟 Magia interfeței: 😊Mai multe emoji drăguțe și cool   /  Îmbunătățiți-vă productivitatea Outlook cu vizualizările cu file  /  Minimizați Outlook în loc să închideți ...

???? Minuni cu un singur clic: Răspundeți tuturor cu atașamentele primite  /   E-mailuri anti-phishing  /  🕘Afișați fusul orar al expeditorului ...

👩🏼‍🤝‍👩🏻 Contacte și calendar: Adăugați în lot contacte din e-mailurile selectate  /  Împărțiți un grup de contact în grupuri individuale  /  Eliminați mementouri de ziua de naștere ...

Peste 100 Caracteristici Așteaptă explorarea ta! Click aici pentru a descoperi mai multe.

 

 

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