Ugrás a tartalomra

Hogyan lehet automatikusan kinyomtatni a mellékleteket, amikor e-mailek érkeznek az Outlookba?

Ez az oktatóanyag bemutatja a VBA-szkript és az Outlook-szabály kombinálásának módszerét, amely segít automatikusan kinyomtatni bizonyos e-mailek mellékleteit, amikor azok megérkeznek az Outlookba.


A mellékletek automatikus nyomtatása bizonyos e-mailek megérkezésekor

Tételezzük fel, hogy egy bizonyos feladótól beérkező e-mailek mellékleteit szeretné automatikusan kinyomtatni. Ezt a következőképpen teheti meg.

1. lépés: Hozzon létre egy szkriptet az Outlookban

Először is létre kell hoznia egy VBA-szkriptet az Outlookban.

1. Indítsa el az Outlook programot, nyomja meg a gombot más + F11 gombok egyszerre a Microsoft Visual Basic for Applications ablak.

2. Ban,-ben Microsoft Visual Basic for Applications ablakban kattintson duplán Project1 > Microsoft Outlook objektumok > ThisOutlookSession megnyitni ThisOutlookSession (kód) ablakot, majd másolja be a következő kódot ebbe a kódablakba.

VBA-kód 1: Automatikusan kinyomtatja a mellékleteket (minden típusú mellékletet), amikor e-mailek megérkeznek

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

Jegyzet: Ez a kód támogatja az e-mailekben kapott minden típusú melléklet nyomtatását. Ha csak a megadott típusú mellékletet szeretné kinyomtatni, például pdf-fájlokat, használja a következő VBA-kódot.

VBA-kód 2: A megadott típusú mellékletek automatikus kinyomtatása e-mailek megérkezésekor

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

Megjegyzések:

1. Mielőtt alkalmazná ezt a VBA-kódot, hogy csak a pdf-fájlt nyomtathassa ki a bejövő e-mailekben, először le kell töltenie és telepítenie kell Adobe Acrobat Reader és állítsa be alapértelmezett pdf-olvasóként a számítógépén.
2. A sorban "pdf" eset, kérem váltson "pdf" a nyomtatni kívánt fájlkiterjesztéshez.

3. Menjen tovább, és kattintson a gombra Eszközök > Hivatkozásokat. A felbukkanóban Referenciák – Projekt1 párbeszédpanelen ellenőrizze a Microsoft Scripting Runtime jelölőnégyzetet, majd kattintson a gombra OK gombot.

4. Mentse el a kódot, és nyomja meg a gombot más + Q gombok a Microsoft Visual Basic for Applications ablak.

Jegyzet: Kérjük, győződjön meg arról, hogy a Engedélyezze az összes makrót opció engedélyezve van az Outlookban. Ezt az opciót az alábbi lépések követésével ellenőrizheti.

2. lépés: Hozzon létre egy szabályt a szkript használatához

Miután hozzáadta a VBA-szkriptet az Outlookhoz, létre kell hoznia egy szabályt a szkript használatához bizonyos feltételek alapján.

1. Lépjen a Kezdőlap fülre, és kattintson a gombra Szabályok > Szabályok és figyelmeztetések kezelése.

2. Ban,-ben Szabályok és riasztások párbeszédpanelen kattintson a Új szabály gombra a szabály létrehozásához.

Tipp: Ha több e-mail fiókot adott hozzá az Outlookhoz, kérjük, adjon meg egy fiókot a Alkalmazza a módosításokat erre a mappára legördülő listából, ahol alkalmazni szeretné a szabályt. Ellenkező esetben az aktuálisan kiválasztott e-mail fiók beérkezett üzenetei közé kerül alkalmazásra.

3. Az elsőben Szabály varázsló párbeszédpanelen válassza ki Alkalmazz szabályt a fogadott üzenetekre a 1 lépés majd kattintson az OK gombra Következő.

4. A másodikban Szabály varázsló párbeszédpanelen:

4.1) Adjon meg egy vagy több feltételt a 1 lépés doboz az Ön igényei szerint;
Ebben az esetben csak a mellékleteket szeretném kinyomtatni a megadott feladótól beérkező e-mailekben. Itt megnézem a emberektől vagy nyilvános csoporttól doboz.
4.2) Kattintson az aláhúzott értékre a 2 lépés mező a feltétel szerkesztéséhez;
4.3) Kattintson Következő. Lásd screenshot:

5. A harmadikban Szabály varázsló párbeszédpanelen az alábbiak szerint kell konfigurálnia.

5.1) A 1. lépés: Válassza ki a művelet(ek) szakaszt, ellenőrizd a futtasson egy szkriptet doboz;
5.2) A 2 lépés részben kattintson az aláhúzott „a script” szövegre;
5.3) A nyílásban Válassza a Szkript lehetőséget párbeszédpanelen kattintson a fent hozzáadott VBA-kód nevére, majd kattintson a gombra RENDBEN;
5.4) Kattintson a gombra Következő gomb. Lásd a képernyőképet:

Tipp: Ha a „futtasson egy szkriptet” lehetőség hiányzik az Ön közül Szabály varázsló, akkor jelenítheti meg az ebben a cikkben említett módszerrel: hiányzó visszaállítás Futtasson egy parancsfájlt az Outlook-szabályban.

6. Aztán még egy Szabály varázsló felbukkan, és kivételeket kér. Szükség esetén kiválaszthatja a kivételeket, ellenkező esetben kattintson a gombra Következő gombot választás nélkül.

7. Az utolsóban Szabály varázsló, meg kell adnia a szabály nevét, majd kattintson a gombra befejez gombot.

8. Ezután visszatér a Szabályok és riasztások párbeszédpanelen belül megtekintheti a létrehozott szabályt, kattintson a OK gombot a teljes beállítás befejezéséhez.

Ezentúl, amikor a megadott személytől e-mail érkezik, a csatolt fájlok automatikusan kinyomtatásra kerülnek.


Kapcsolódó cikkek

Csak egy e-mailből vagy kiválasztott e-mailekből nyomtasson mellékletet az Outlook programban
Az Outlookban kinyomtathatja az e-maileket, de csak egy e-mailből vagy kiválasztott e-mailekből nyomtatta ki a mellékleteket az Outlookban? Ez a cikk bemutatja a feladat megoldásának trükkjeit.

Csak egy e-mail üzenet fejlécének nyomtatása az Outlook programban
Amikor egy e-mailt nyomtat az Outlookban, az üzenet fejlécét és törzsét is kinyomtatja. Néhány speciális esetben azonban előfordulhat, hogy csak ki kell nyomtatnia az üzenet fejlécét a tárgy, a feladó, a címzett stb. feltüntetésével. Ez a cikk két megoldást mutat be erre.

Nyomtasson ki egy naptárt egy megadott/egyéni dátumtartományban az Outlook programban
Normál esetben, ha az Outlook hónap nézetében nyomtat egy naptárt, a program automatikusan kiválasztja az aktuálisan kiválasztott dátumot tartalmazó hónapot. Előfordulhat azonban, hogy a naptárt egyéni dátumtartományon belül kell kinyomtatnia, például 3 hónapon, féléven stb. Ebben a cikkben bemutatjuk a megoldást.

Nyomtasson ki egy névjegyet képpel az Outlookban
Normál esetben a névjegy képe nem kerül kinyomtatásra, amikor az Outlook programban kinyomtatja a névjegyet. De néha sokkal lenyűgözőbb lesz egy névjegy kinyomtatása a képével. Ez a cikk néhány megoldást ismertet a megvalósítás érdekében.

Nyomtasson ki egy e-mailt az Outlook programban
Ha kapott egy e-mailt, és megállapította, hogy az e-mail tartalmának egy részét ki kell nyomtatni a teljes üzenet nyomtatása helyett, mit tennél? Valójában az Outlook internetes böngészők, például a Firefox és az Internet Explorer segítségével segíthet ennek a műveletnek a megvalósításában. Itt például az Internet böngészőket vesszük figyelembe. Kérjük, tekintse meg a következő oktatóanyagokat.

További cikkek az Outlookban való nyomtatásról...


A legjobb irodai hatékonyságnövelő eszközök

Kutools az Outlook számára - Több mint 100 hatékony funkció az Outlook feltöltéséhez

🤖 AI Mail Assistant: Azonnali profi e-mailek mesterséges intelligencia varázslattal – egyetlen kattintással zseniális válaszok, tökéletes hangnem, többnyelvű elsajátítás. Alakítsa át az e-mailezést könnyedén! ...

???? E-mail automatizálás: Hivatalon kívül (POP és IMAP esetén elérhető)  /  Ütemezze az e-mailek küldését  /  Automatikus CC/BCC szabályok szerint e-mail küldésekor  /  Automatikus továbbítás (Speciális szabályok)   /  Automatikus üdvözlet hozzáadása   /  A több címzettnek szóló e-mailek automatikus felosztása egyedi üzenetekre ...

📨 Email Management: Könnyen visszahívhatja az e-maileket  /  Blokkolja az alanyok és mások átverő e-mailjeit  /  Törölje az ismétlődő e-maileket  /  Részletes keresés  /  Mappák összevonása ...

📁 Attachments ProKötegelt mentés  /  Batch Detach  /  Batch tömörítés  /  Automatikus mentés   /  Automatikus leválasztás  /  Automatikus tömörítés ...

🌟 Interface Magic: 😊További szép és menő hangulatjelek   /  Növelje Outlook termelékenységét a füles nézetekkel  /  Minimalizálja az Outlookot a bezárás helyett ...

👍 Csodák egy kattintással: Válasz mindenkinek a bejövő mellékletekkel  /   Adathalászat elleni e-mailek  /  🕘A feladó időzónájának megjelenítése ...

👩🏼‍🤝‍👩🏻 Névjegyek és naptár: Névjegyek kötegelt hozzáadása a kiválasztott e-mailekből  /  Egy kapcsolattartó csoport felosztása egyéni csoportokra  /  Távolítsa el a születésnapi emlékeztetőket ...

Több, mint 100 Jellemzők Várja felfedezését! Kattintson ide, ha többet szeretne megtudni.

 

 

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