Skip i'r prif gynnwys

Sut i argraffu atodiadau yn awtomatig pan fydd e-byst yn cyrraedd Outlook?

Mae'r tiwtorial hwn yn dangos dull o gyfuno sgript VBA a rheol Outlook i'ch helpu chi i argraffu atodiadau o e-byst penodol yn awtomatig pan fyddant yn cyrraedd Outlook.


Argraffwch atodiadau yn awtomatig pan fydd rhai e-byst penodol yn cyrraedd

Gan dybio, rydych chi am argraffu atodiadau e-byst sy'n dod i mewn gan anfonwr penodol yn awtomatig. Gallwch chi wneud fel a ganlyn i'w gyflawni.

Cam 1: Creu sgript yn Outlook

Yn gyntaf, mae angen i chi greu sgript VBA yn Outlook.

1. Lansio eich Rhagolwg, pwyswch y Alt + F11 allweddi ar yr un pryd i agor y Microsoft Visual Basic ar gyfer Ceisiadau ffenestr.

2. Yn y Microsoft Visual Basic ar gyfer Ceisiadau ffenestr, cliciwch ddwywaith ar Project1 > Gwrthrychau Microsoft Outlook > SesiwnOutlook i agor y ThisOutlookSession (Cod) ffenestr, ac yna copïwch y cod canlynol i'r ffenestr cod hon.

Cod VBA 1: Argraffu atodiadau yn awtomatig (pob math o atodiadau) pan fydd e-byst yn cyrraedd

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

Nodyn: Mae'r cod hwn yn cefnogi argraffu pob math o atodiadau a dderbynnir mewn e-byst. Os ydych chi am argraffu'r math penodedig o atodiad yn unig, fel ffeiliau pdf, cymhwyswch y cod VBA canlynol.

Cod VBA 2: Argraffwch yn awtomatig y math penodedig o atodiadau pan fydd e-byst yn cyrraedd

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

Nodiadau:

1. Cyn cymhwyso'r cod VBA hwn i argraffu'r ffeil pdf yn unig yn y negeseuon e-bost sy'n dod i mewn, yn gyntaf mae angen i chi lawrlwytho a gosod Darllenydd Adobe Acrobat a'i osod fel y darllenydd pdf rhagosodedig yn eich cyfrifiadur.
2. Yn y llinell Achos "pdf", os gwelwch yn dda newid "pdf" i'r estyniad ffeil rydych chi am ei argraffu.

3. Ewch ymlaen a chliciwch offer > Cyfeiriadau. Yn y popping up Cyfeiriadau – Prosiect1 blwch deialog, gwiriwch y Amser Rhedeg Sgriptio Microsoft blwch, ac yna cliciwch ar y OK botwm.

4. Cadwch y cod a gwasgwch y Alt + Q allweddi i gau'r Microsoft Visual Basic ar gyfer Ceisiadau ffenestr.

Nodyn: Gwnewch yn siŵr bod y Galluogi pob macros opsiwn wedi'i alluogi yn eich Outlook. Gallwch wirio'r opsiwn hwn trwy ddilyn y camau a ddangosir isod.

Cam 2: Adeiladu rheol i ddefnyddio'r sgript

Ar ôl ychwanegu'r sgript VBA yn Outlook, mae angen i chi greu rheol i ddefnyddio'r sgript yn seiliedig ar amodau penodol.

1. Ewch i'r tab Cartref, cliciwch Rheolau > Rheoli Rheolau a Rhybuddion.

2. Yn y Rheolau a Rhybuddion blwch deialog, cliciwch y Rheol Newydd botwm i greu rheol.

Awgrym: Os ydych wedi ychwanegu cyfrifon e-bost lluosog at eich Outlook, nodwch gyfrif yn y Cymhwyso newidiadau i'r ffolder hon gwymplen lle rydych chi am gymhwyso'r rheol. Fel arall, bydd yn cael ei gymhwyso i fewnflwch y cyfrif e-bost a ddewiswyd ar hyn o bryd.

3. Yn y cyntaf Dewin Rheolau blwch deialog, dewiswch Gwnewch gais ar y negeseuon a gefais yn y 1 cam blwch, ac yna cliciwch Nesaf.

4. Yn yr ail Dewin Rheolau blwch deialog, mae angen i chi:

4.1) Nodwch un neu fwy o amodau yn y 1 cam blwch yn ôl eich anghenion;
Yn yr achos hwn, rwyf am argraffu'r atodiadau mewn negeseuon e-bost sy'n dod i mewn gan anfonwr penodedig yn unig. Yma, yr wyf yn gwirio y gan bobl neu grŵp cyhoeddus blwch.
4.2) Cliciwch ar y gwerth wedi'i danlinellu yn y 2 cam blwch i olygu'r cyflwr;
4.3) Cliciwch Nesaf. Gweler y screenshot:

5. Yn y trydydd Dewin Rheolau blwch deialog, mae angen i chi ffurfweddu fel a ganlyn.

5.1) Yn y Cam 1: Dewiswch adran cam(au) gweithredu, gwiriwch y rhedeg sgript blwch;
5.2) Yn y 2 cam adran, cliciwch ar y testun wedi'i danlinellu “sgript”;
5.3) Yn yr agoriad Dewiswch Sgript blwch deialog, cliciwch ar enw'r cod VBA a ychwanegwyd gennych uchod, ac yna cliciwch IAWN;
5.4) Cliciwch y Digwyddiadau botwm. Gweler y screenshot:

Awgrym: Os yw'r “rhedeg sgript” opsiwn ar goll yn eich Dewin Rheolau, gallwch ei arddangos trwy ddilyn y dull a grybwyllir yn yr erthygl hon: adfer ar goll Run A Script pption yn Outlook rheol.

6. Yna un arall Dewin Rheolau pops i fyny yn gofyn am eithriadau. Gallwch ddewis yr eithriadau os oes angen, fel arall, cliciwch ar y Digwyddiadau botwm heb unrhyw ddewisiadau.

7. Yn yr olaf Dewin Rheolau, mae angen i chi nodi enw ar gyfer y rheol, ac yna cliciwch ar y Gorffen botwm.

8. Yna mae'n dychwelyd i'r Rheolau a Rhybuddion blwch deialog, gallwch weld y rheol a grewyd gennych a restrir y tu mewn, cliciwch ar y OK botwm i orffen y gosodiadau cyfan.

O hyn ymlaen, pan dderbynnir e-bost gan y person penodedig, bydd y ffeiliau atodedig yn cael eu hargraffu'n awtomatig.


Erthyglau perthnasol

Dim ond Argraffu Atodiad(S) O Un E-bost Neu E-byst Dethol Yn Outlook
Yn Outlook, gallwch chi argraffu'r negeseuon e-bost, ond a ydych chi wedi argraffu'r atodiadau o un e-bost yn unig neu e-byst dethol yn Outlook? Mae'r erthygl hon yn cyflwyno'r triciau ar ddatrys y swydd hon.

Dim ond Argraffu Pennawd Neges E-bost Yn Outlook
Wrth argraffu e-bost yn Outlook, bydd yn argraffu pennawd neges a chorff neges yn yr e-bost. Fodd bynnag, mewn rhai achosion arbennig, efallai y bydd angen i chi argraffu pennawd y neges gyda'r pwnc, anfonwr, derbynwyr, ac ati Bydd yr erthygl hon yn cyflwyno dau ateb i'w wneud.

Argraffu Calendr Mewn Ystod Dyddiad Penodedig / Cwsmer Yn Outlook
Fel arfer, wrth argraffu calendr yn Month view yn Outlook, bydd yn dewis y mis sy'n cynnwys y dyddiad a ddewiswyd ar hyn o bryd yn awtomatig. Ond, efallai y bydd angen i chi argraffu'r calendr o fewn ystod dyddiad arferol, megis 3 mis, hanner y flwyddyn, ac ati Bydd yr erthygl hon yn cyflwyno'r ateb i chi.

Argraffu Cyswllt Gyda Llun Yn Outlook
Fel rheol, ni fydd llun cyswllt yn cael ei argraffu wrth argraffu'r cyswllt yn Outlook. Ond weithiau, bydd yn fwy trawiadol argraffu cyswllt gyda'i lun. Bydd yr erthygl hon yn cyflwyno rhai cylchoedd gwaith i'w gyflawni.

Argraffu Detholiad O E-bost Yn Outlook
Pe byddech chi'n derbyn neges e-bost ac wedi darganfod bod yna ddetholiad o'r cynnwys e-bost mae angen ei argraffu yn lle argraffu'r neges gyfan, beth fyddech chi'n ei wneud? Mewn gwirionedd, gall Outlook eich helpu i gyflawni'r llawdriniaeth hon gyda chymorth porwyr rhyngrwyd, fel y Firefox a'r Internet Explorer. Yma, byddaf yn cymryd y porwyr Rhyngrwyd er enghraifft. Edrychwch ar y tiwtorialau canlynol.

Mwy o erthyglau am "argraffu yn Outlook"...


Offer Cynhyrchiant Swyddfa Gorau

Kutools ar gyfer Rhagolwg - Dros 100 o Nodweddion Pwerus i Werthu Eich Outlook

🤖 Cynorthwy-ydd Post AI: E-byst pro ar unwaith gyda hud AI - un clic i atebion athrylith, tôn berffaith, meistrolaeth amlieithog. Trawsnewid e-bostio yn ddiymdrech! ...

📧 E-bostio Automation: Allan o'r Swyddfa (Ar gael ar gyfer POP ac IMAP)  /  Amserlen Anfon E-byst  /  Auto CC/BCC gan Reolau Wrth Anfon E-bost  /  Awto Ymlaen (Rheolau Uwch)   /  Auto Ychwanegu Cyfarchiad   /  Rhannwch E-byst Aml-Dderbynnydd yn Negeseuon Unigol yn Awtomatig ...

📨 Rheoli E-bost: Dwyn i gof E-byst yn Hawdd  /  Rhwystro E-byst Sgam gan Bynciau ac Eraill  /  Dileu E-byst Dyblyg  /  Chwilio Manwl  /  Cydgrynhoi Ffolderi ...

📁 Ymlyniadau ProArbed Swp  /  Swp Datgysylltu  /  Cywasgu Swp  /  Auto Achub   /  Datgysylltiad Auto  /  Cywasgiad Auto ...

🌟 Rhyngwyneb Hud: 😊Mwy o Emojis Pretty a Cŵl   /  Rhowch hwb i'ch Cynhyrchiant Outlook gyda Golygfeydd Tabbed  /  Lleihau Outlook Yn lle Cau ...

???? Rhyfeddodau un clic: Ateb Pawb ag Ymlyniadau Dod i Mewn  /   E-byst Gwrth-Gwe-rwydo  /  🕘Dangos Parth Amser yr Anfonwr ...

👩🏼‍🤝‍👩🏻 Cysylltiadau a Chalendr: Swp Ychwanegu Cysylltiadau O E-byst Dethol  /  Rhannwch Grŵp Cyswllt i Grwpiau Unigol  /  Dileu Atgoffa Pen-blwydd ...

Dros Nodweddion 100 Aros Eich Archwiliad! Cliciwch Yma i Ddarganfod Mwy.

 

 

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