Preskoči na glavno vsebino

Kako samodejno natisniti priloge, ko e-poštna sporočila prispejo v Outlook?

Ta vadnica prikazuje način združevanja skripta VBA in Outlookovega pravila, ki vam pomaga samodejno natisniti priloge določenih e-poštnih sporočil, ko prispejo v Outlook.


Samodejno natisnite priloge, ko prispejo določena e-poštna sporočila

Predpostavimo, da želite samodejno natisniti priloge dohodnih e-poštnih sporočil določenega pošiljatelja. Če želite to narediti, lahko storite naslednje.

korak: Ustvarite skript v Outlooku

Najprej morate ustvariti skript VBA v Outlooku.

1. Zaženite Outlook, pritisnite druga + F11 tipke hkrati, da odprete Microsoft Visual Basic za aplikacije okno.

2. V Ljubljani Microsoft Visual Basic za aplikacije okno, dvokliknite na Project1 > Predmeti Microsoft Outlook > Ta OutlookSession da odprete ThisOutlookSession (koda) okno in nato v to kodno okno kopirajte naslednjo kodo.

Koda VBA 1: samodejno natisnite priloge (vse vrste prilog), ko prispejo e-poštna sporočila

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

Opomba: Ta koda podpira tiskanje vseh vrst prilog, prejetih v e-poštnih sporočilih. Če želite natisniti samo določeno vrsto priloge, na primer datoteke pdf, uporabite naslednjo kodo VBA.

Koda VBA 2: samodejno natisnite določeno vrsto prilog, ko prispejo e-poštna sporočila

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

Opombe:

1. Preden uporabite to kodo VBA za tiskanje samo datoteke pdf v dohodni e-pošti, morate najprej prenesti in namestiti Adobe Acrobat Reader in ga nastavite kot privzeti bralnik pdf v vašem računalniku.
2. V vrsti Zadeva "pdf", prosim, spremenite "pdf" na pripono datoteke, ki jo želite natisniti.

3. Pojdite naprej in kliknite Orodja > Reference. V pojavnem oknu Reference – Projekt1 pogovorno okno, preverite Izvajanje Microsoftovih skriptov in nato kliknite OK gumb.

4. Shranite kodo in pritisnite druga + Q tipke za zapiranje Microsoft Visual Basic za aplikacije okno.

Opomba: Prosimo, poskrbite, da bo Omogoči vse makre možnost je omogočena v vašem Outlooku. To možnost lahko preverite tako, da sledite spodnjim korakom.

2. korak: Zgradite pravilo za uporabo skripta

Ko dodate skript VBA v Outlook, morate ustvariti pravilo za uporabo skripta na podlagi določenih pogojev.

1. Pojdite na zavihek Domov in kliknite Pravila > Upravljanje pravil in opozoril.

2. V Ljubljani Pravila in opozorila pogovorno okno, kliknite na Novo pravilo gumb, da ustvarite pravilo.

Nasvet: Če ste v Outlook dodali več e-poštnih računov, navedite račun v Uporabi spremembe v tej mapi spustni seznam, kjer želite uporabiti pravilo. V nasprotnem primeru bo uporabljen v mapi Prejeto trenutno izbranega e-poštnega računa.

3. V prvem Čarovnik za pravila pogovorno okno, izberite Uporabi pravilo o sporočilih, ki jih prejmem v korak 1 in nato kliknite Naslednji.

4. V drugem Čarovnik za pravila pogovorno okno, morate:

4.1) Določite enega ali več pogojev v korak 1 škatla glede na vaše potrebe;
V tem primeru želim natisniti samo priloge v dohodnih e-poštnih sporočilih določenega pošiljatelja. Evo, preverim od ljudi ali javne skupine škatla.
4.2) Kliknite podčrtano vrednost v korak 2 polje za urejanje pogoja;
4.3) Kliknite Naslednji. Oglejte si posnetek zaslona:

5. V tretjem Čarovnik za pravila pogovorno okno, morate konfigurirati na naslednji način.

5.1) V 1. korak: Izberite razdelek za dejanja, preverite zaženite skript škatla;
5.2) V korak 2 razdelku kliknite podčrtano besedilo »skript«;
5.3) V uvodu Izberite Script pogovornem oknu, kliknite ime kode VBA, ki ste jo dodali zgoraj, in nato kliknite V REDU;
5.4) Kliknite Naslednji . Oglejte si posnetek zaslona:

Nasvet: Če »zaženite skript” manjka možnost v vašem Čarovnik za pravila, ga lahko prikažete na način, omenjen v tem članku: obnovite manjkajočo možnost Zaženi skript v pravilu Outlooka.

6. Potem še eno Čarovnik za pravila se pojavi in ​​prosi za izjeme. Po potrebi lahko izberete izjeme, sicer pa kliknite na Naslednji gumb brez izbire.

7. V zadnjem Čarovnik za pravila, morate določiti ime za pravilo in nato klikniti Konec gumb.

8. Potem se vrne v Pravila in opozorila V pogovornem oknu si lahko ogledate pravilo, ki ste ga ustvarili, navedeno znotraj, kliknite na OK , da končate celotne nastavitve.

Od zdaj naprej, ko prejmemo e-pošto določene osebe, se priložene datoteke samodejno natisnejo.


Sorodni članki

Tiskajte samo prilogo(-e) iz enega e-poštnega sporočila ali izbranih e-poštnih sporočil v Outlooku
V Outlooku lahko natisnete e-poštna sporočila, vendar ste priloge natisnili samo iz enega e-poštnega sporočila ali izbranih e-poštnih sporočil v Outlooku? Ta članek predstavlja trike za reševanje tega dela.

Natisnite samo glavo sporočila e-pošte v Outlooku
Ko tiskate e-pošto v Outlooku, bo natisnil tako glavo sporočila kot telo sporočila v e-pošti. Vendar pa boste v nekaterih posebnih primerih morda morali samo natisniti glavo sporočila z zadevo, pošiljateljem, prejemniki itd. Ta članek bo predstavil dve rešitvi za to.

Natisnite koledar v določenem/prilagojenem časovnem obdobju v Outlooku
Običajno bo pri tiskanju koledarja v mesečnem pogledu v Outlooku samodejno izbral mesec, ki vsebuje trenutno izbrani datum. Morda pa boste morali koledar natisniti v časovnem obdobju po meri, kot so 3 mesece, pol leta itd. Ta članek vam bo predstavil rešitev.

Natisnite stik s sliko v Outlooku
Pri tiskanju stika v Outlooku se slika stika običajno ne natisne. Včasih pa bo bolj impresivno natisniti stik z njegovo sliko. Ta članek bo predstavil nekaj rešitev za to.

Natisnite izbor e-pošte v Outlooku
Če bi prejeli e-poštno sporočilo in ugotovili, da je treba namesto tiskanja celotnega sporočila natisniti izbrano vsebino e-pošte, kaj bi storili? Pravzaprav vam Outlook lahko pomaga pri tej operaciji s pomočjo internetnih brskalnikov, kot sta Firefox in Internet Explorer. Tu bom na primer vzel internetne brskalnike. Oglejte si naslednje vaje.

Več člankov o "tiskanju v Outlooku" ...


Najboljša pisarniška orodja za produktivnost

Kutools za Outlook - Več kot 100 zmogljivih funkcij za nadgradnjo vašega Outlooka

🤖 AI poštni pomočnik: Takojšnja profesionalna e-poštna sporočila z umetno inteligenco – z enim klikom do genialnih odgovorov, popoln ton, večjezično znanje. Preoblikujte pošiljanje e-pošte brez napora! ...

📧 Avtomatizacija e-pošte: Odsoten (na voljo za POP in IMAP)  /  Načrtujte pošiljanje e-pošte  /  Samodejna CC/BCC po pravilih pri pošiljanju e-pošte  /  Samodejno naprej (napredna pravila)   /  Samodejno dodaj pozdrav   /  E-poštna sporočila več prejemnikov samodejno razdeli na posamezna sporočila ...

📨 Email upravljanje: Enostaven priklic e-pošte  /  Blokiraj prevarantska e-poštna sporočila glede na teme in druge  /  Izbriši podvojena e-poštna sporočila  /  napredno iskanje  /  Združite mape ...

📁 Priloge ProShrani paket  /  Batch Detach  /  Paketno stiskanje  /  Samodejno shranite   /  Samodejno loči  /  Samodejno stiskanje ...

🌟 Vmesnik Magic: 😊Več lepih in kul emojijev   /  Povečajte Outlookovo produktivnost s pogledi z zavihki  /  Minimizirajte Outlook, namesto da bi ga zaprli ...

???? Čudeži z enim klikom: Odgovori vsem z dohodnimi prilogami  /   E-poštna sporočila proti lažnemu predstavljanju  /  🕘Pokaži pošiljateljev časovni pas ...

👩🏼‍🤝‍👩🏻 Stiki in koledar: Paketno dodajanje stikov iz izbranih e-poštnih sporočil  /  Razdelite skupino stikov na posamezne skupine  /  Odstranite opomnike za rojstni dan ...

Over 100 Lastnosti Čakajte na svoje raziskovanje! Kliknite tukaj, če želite odkriti več.

 

 

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