Բաց թողնել հիմնական բովանդակությունը

Ինչպե՞ս ավտոմատ կերպով տպել հավելվածները, երբ նամակները հասնում են Outlook-ում:

Այս ձեռնարկը ցույց է տալիս VBA սկրիպտը և Outlook կանոնը համատեղելու մեթոդ, որը կօգնի ձեզ ավտոմատ կերպով տպել որոշ էլ. նամակների կցորդները, երբ դրանք հասնում են Outlook-ին:


Ավտոմատ տպել հավելվածները, երբ որոշակի նամակներ են գալիս

Ենթադրենք, դուք ցանկանում եք ինքնաբերաբար տպել մուտքային նամակների կցորդները որոշակի ուղարկողի կողմից: Դա անելու համար կարող եք անել հետևյալը.

Քայլ 1. Ստեղծեք սցենար Outlook-ում

Նախ, դուք պետք է ստեղծեք VBA սցենար Outlook-ում:

1. Գործարկեք ձեր Outlook- ը, սեղմեք այն ալտ + F11 ստեղները միաժամանակ բացելու համար Microsoft Visual Basic հավելվածների համար պատուհան.

2. Մեջ Microsoft Visual Basic հավելվածների համար պատուհանը, կրկնակի սեղմեք Project1 > Microsoft Outlook օբյեկտներ > ԱյսOutlookSession- ը բացելու համար ThisOutlookSession (ծածկագիր) պատուհանում, այնուհետև պատճենեք հետևյալ կոդը այս կոդի պատուհանում:

VBA կոդ 1. ավտոմատ կերպով տպել հավելվածները (բոլոր տեսակի կցորդները), երբ նամակները հասնում են

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

Նշում: Այս ծածկագիրը աջակցում է էլեկտրոնային փոստով ստացված բոլոր տեսակի հավելվածների տպագրմանը: Եթե ​​ցանկանում եք տպել միայն նշված տեսակի հավելվածը, օրինակ՝ pdf ֆայլերը, խնդրում ենք կիրառել հետևյալ VBA կոդը:

VBA կոդ 2. ավտոմատ կերպով տպել նշված տեսակի կցորդները, երբ նամակները հասնում են

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

Notes:

1. Նախքան այս VBA կոդը կիրառելը՝ մուտքային նամակներում միայն pdf ֆայլը տպելու համար, նախ պետք է ներբեռնել և տեղադրել Adobe Acrobat Reader- ը և սահմանեք այն որպես լռելյայն pdf ընթերցող ձեր համակարգչում:
2. Շարքում Պատյան «pdf»խնդրում եմ փոխեք «pdf» ֆայլի ընդլայնմանը, որը ցանկանում եք տպել:

3. Շարունակեք և սեղմեք Գործիքներ > Հղումներով. Պատուհանման մեջ Հղումներ – Նախագիծ 1 երկխոսության տուփ, ստուգեք Microsoft Scripting Runtime տուփը, ապա կտտացրեք OK կոճակը:

4. Պահեք կոդը և սեղմեք կոճակը ալտ + Q ստեղները փակելու համար Microsoft Visual Basic հավելվածների համար պատուհան.

Նշում: Խնդրում ենք համոզվել, որ Միացնել բոլոր մակրոները տարբերակը միացված է ձեր Outlook-ում: Դուք կարող եք ստուգել այս տարբերակը՝ հետևելով ստորև ներկայացված քայլերին:

Քայլ 2. Ստեղծեք կանոն՝ սցենարն օգտագործելու համար

Outlook-ում VBA սկրիպտը ավելացնելուց հետո դուք պետք է ստեղծեք կանոն՝ որոշակի պայմանների հիման վրա սկրիպտը օգտագործելու համար:

1. Գնացեք «Տուն» ներդիր, սեղմեք Կանոններ > Կառավարեք կանոններն ու ահազանգերը.

2. Մեջ Կանոններ և ահազանգեր երկխոսության տուփ, կտտացրեք Նոր կանոն կանոն ստեղծելու կոճակը:

Հուշում. Եթե ​​դուք ավելացրել եք բազմաթիվ էլփոստի հաշիվներ ձեր Outlook-ում, խնդրում ենք նշել հաշիվը Կիրառեք փոփոխություններ այս թղթապանակում բացվող ցուցակը, որտեղ ցանկանում եք կիրառել կանոնը: Հակառակ դեպքում այն ​​կկիրառվի ներկայումս ընտրված էլփոստի հաշվի մուտքի արկղում:

3. Առաջինում Կանոնների մոգ երկխոսության տուփ, ընտրեք Կիրառեք այն կանոնները, որոնք ես ստանում եմ է Քայլ 1 տուփը, ապա կտտացրեք Next.

4. Երկրորդում Կանոնների մոգ երկխոսության տուփ, անհրաժեշտ է.

4.1) Նշեք մեկ կամ մի քանի պայմաններ Քայլ 1 տուփ ըստ ձեր կարիքների;
Այս դեպքում ես ուզում եմ տպել միայն կցորդները նշված ուղարկողի մուտքային նամակներում: Ահա, ես ստուգում եմ մարդկանցից կամ հասարակական խմբից տուփ:
4.2) Սեղմեք ընդգծված արժեքի վրա Քայլ 2 տուփ՝ պայմանը խմբագրելու համար;
4.3) Կտտացրեք Next. Տեսեք,

5. Երրորդում Կանոնների մոգ երկխոսության տուփ, դուք պետք է կազմաձևեք հետևյալը.

5.1) Ի Քայլ 1. Ընտրեք գործողություն(ներ) բաժինը, ստուգեք գործարկել սցենար տուփ;
5.2) Ի Քայլ 2 բաժինը, սեղմեք ընդգծված տեքստը «մի սցենար»;
5.3) Բացման մեջ Ընտրեք սցենար երկխոսության վանդակում, սեղմեք վերևում ավելացրած VBA կոդի անունը և սեղմեք ԼԱՎ;
5.4) Կտտացրեք այն հաջորդ կոճակ Տեսեք,

Հուշում. Եթե ​​"գործարկել սցենար” տարբերակը բացակայում է ձեր մեջ Կանոնների մոգ, կարող եք ցուցադրել այն՝ հետևելով այս հոդվածում նշված մեթոդին. վերականգնել բացակայող Run A Script pption-ը Outlook կանոնում.

6. Հետո մեկ այլ Կանոնների մոգ հայտնվում է բացառություններ խնդրելով: Անհրաժեշտության դեպքում կարող եք ընտրել բացառությունները, հակառակ դեպքում սեղմեք կոճակը հաջորդ կոճակ առանց որևէ ընտրության։

7. Վերջինում Կանոնների մոգ, դուք պետք է նշեք կանոնի անունը, այնուհետև սեղմեք կոճակը Ավարտել կոճակը:

8. Ապա այն վերադառնում է դեպի Կանոններ և ահազանգեր երկխոսության վանդակում, դուք կարող եք տեսնել ձեր ստեղծած կանոնը, որը նշված է ներսում, սեղմեք կոճակը OK կոճակը ՝ ամբողջ պարամետրերն ավարտելու համար:

Այսուհետ, երբ նշված անձից նամակ ստացվի, կցված ֆայլերը ավտոմատ կերպով կտպվեն։


Առնչվող հոդվածներ

Outlook-ում միայն մեկ էլփոստից կամ ընտրված նամակներից տպել հավելված(ներ):
Outlook-ում դուք կարող եք տպել նամակները, բայց արդյո՞ք տպել եք կցորդները միայն մեկ էլփոստից կամ ընտրված էլփոստից Outlook-ում: Այս հոդվածը ներկայացնում է այս աշխատանքը լուծելու հնարքները։

Outlook-ում էլփոստի միայն տպագիր հաղորդագրության վերնագիր
Outlook-ում էլփոստ տպելիս այն կտպագրի և՛ հաղորդագրության վերնագիրը, և՛ հաղորդագրության տեքստը էլ. Այնուամենայնիվ, որոշ հատուկ դեպքերում ձեզ կարող է պարզապես անհրաժեշտ լինել տպել հաղորդագրության վերնագիրը՝ թեմայի, ուղարկողի, ստացողների և այլնի հետ միասին: Այս հոդվածը կներկայացնի երկու լուծում դա անելու համար:

Տպել օրացույց Outlook-ում նշված/անհատականացված ամսաթվերի միջակայքում
Սովորաբար, Outlook-ում ամսական տեսքով օրացույց տպելիս այն ավտոմատ կերպով կընտրի տվյալ պահին ընտրված ամսաթիվը պարունակող ամիսը: Այնուամենայնիվ, ձեզ կարող է անհրաժեշտ լինել տպել օրացույցը հատուկ ամսաթվերի միջակայքում, օրինակ՝ 3 ամիս, կես տարի և այլն: Այս հոդվածը կներկայացնի լուծումը ձեզ համար:

Տպել կոնտակտը նկարի հետ Outlook-ում
Սովորաբար, կոնտակտային պատկերը չի տպվում Outlook- ում կոնտակտը տպելիս: Բայց երբեմն ավելի տպավորիչ կլինի տպել կոնտակտ իր նկարով: Այս հոդվածը կներկայացնի որոշ լուծումներ `այն իրականացնելու համար:

Outlook-ում էլփոստի ընտրանի տպեք
Եթե ​​դուք էլ-նամակ ստանաք և տեսնեք, որ կա էլ. Փոստի բովանդակության ընտրություն, որն անհրաժեշտ է տպել ամբողջ հաղորդագրությունը տպելու փոխարեն, ի՞նչ կանեիք: Իրականում, Outlook- ը կարող է օգնել ձեզ հասնել այս գործողությանը ինտերնետ զննարկիչների միջոցով, ինչպիսիք են Firefox- ը և Internet Explorer- ը: Այստեղ ես օրինակ կվերցնեմ ինտերնետային զննարկիչները: Խնդրում ենք դիտել հետևյալ ձեռնարկները:

Լրացուցիչ հոդվածներ «Տպագրություն Outlook»-ում...


Գրասենյակի արտադրողականության լավագույն գործիքները

Outlook- ի համար նախատեսված գործիքներ - Ավելի քան 100 հզոր գործառույթ՝ ձեր Outlook-ը լիցքավորելու համար

🤖 AI Փոստի օգնական: Ակնթարթային պրոֆեսիոնալ նամակներ AI մոգությամբ. մեկ սեղմումով հանճարեղ պատասխաններ, կատարյալ հնչերանգներ, բազմալեզու վարպետություն: Փոխակերպեք էլ. փոստը առանց ջանքերի: ...

📧 Email ավտոմատացում: Գրասենյակից դուրս (հասանելի է POP-ի և IMAP-ի համար)  /  Ժամանակացույց ուղարկել նամակներ  /  Ավտոմատ CC/BCC էլփոստ ուղարկելիս կանոններով  /  Ավտոմատ փոխանցում (Ընդլայնված կանոններ)   /  Ավտոմատ ավելացնել ողջույնները   /  Ավտոմատ կերպով բաժանել բազմասերիստացող նամակները առանձին հաղորդագրությունների ...

📨 էլեկտրոնային կառավարման: Հեշտությամբ հիշեք նամակները  /  Արգելափակել խարդախության նամակները ըստ առարկաների և այլոց  /  Deleteնջել կրկնօրինակ նամակները  /  Ընդլայնված որոնում  /  Համախմբել Թղթապանակները ...

📁 Հավելվածներ ProԽմբաքանակի պահպանում  /  Խմբաքանակի անջատում  /  Խմբաքանակային կոմպրես  /  Auto Save- ը   /  Ավտոմատ անջատում  /  Ավտոմատ սեղմում ...

🌟 Ինտերֆեյս Magic: 😊Ավելի գեղեցիկ և զով էմոջիներ   /  Բարձրացրեք ձեր Outlook-ի արտադրողականությունը ներդիրներով դիտումների միջոցով  /  Նվազագույնի հասցնել Outlook-ը փակելու փոխարեն ...

???? Մեկ սեղմումով Հրաշքներ: Պատասխանել բոլորին մուտքային հավելվածներով  /   Հակաֆիշինգի էլ. նամակներ  /  🕘Ցուցադրել ուղարկողի ժամային գոտին ...

👩🏼‍🤝‍👩🏻 Կոնտակտներ և օրացույց: Խմբաքանակի ավելացրեք կոնտակտներ ընտրված էլ  /  Կոնտակտային խումբը բաժանեք առանձին խմբերի  /  Հեռացնել ծննդյան հիշեցումները ...

Over 100 Նկարագրություն Սպասեք ձեր հետազոտությանը: Սեղմեք այստեղ՝ ավելին բացահայտելու համար:

 

 

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