انتقل إلى المحتوى الرئيسي

كيفية طباعة المرفقات تلقائيًا عند وصول رسائل البريد الإلكتروني في Outlook؟

يوضح هذا البرنامج التعليمي طريقة لدمج برنامج VBA النصي وقاعدة Outlook لمساعدتك على طباعة مرفقات رسائل بريد إلكتروني معينة تلقائيًا عند وصولها إلى Outlook.


قم بطباعة المرفقات تلقائيًا عند وصول رسائل بريد إلكتروني معينة

لنفترض أنك تريد طباعة مرفقات رسائل البريد الإلكتروني الواردة من مرسل معين تلقائيًا. يمكنك القيام بما يلي لإنجازه.

الخطوة 1: قم بإنشاء برنامج نصي في Outlook

أولاً ، تحتاج إلى إنشاء برنامج نصي لـ VBA في Outlook.

1. قم بتشغيل Outlook ، اضغط على قديم + F11 مفاتيح في نفس الوقت لفتح ميكروسوفت فيسوال باسيك للتطبيقات نافذة.

2. في ال ميكروسوفت فيسوال باسيك للتطبيقات نافذة ، انقر نقرًا مزدوجًا فوق Project1 > كائنات Microsoft Outlook > هذه الجلسة لفتح ThisOutlookSession (رمز) نافذة ، ثم انسخ الكود التالي في نافذة الكود هذه.

كود فبا 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 التالي.

كود فبا 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

ملاحظة:

1. قبل تطبيق رمز VBA هذا لطباعة ملف pdf فقط في رسائل البريد الإلكتروني الواردة ، تحتاج أولاً إلى التنزيل والتثبيت أدوبي أكروبات ريدر وقم بتعيينه كقارئ pdf الافتراضي في جهاز الكمبيوتر الخاص بك.
2. في السطر الحالة "pdf"، من فضلك غير "بي دي إف" إلى امتداد الملف الذي تريد طباعته.

3. انطلق وانقر الأدوات > المراجع. في ظهرت المراجع - مشروع 1 مربع الحوار، والتحقق من وقت تشغيل البرمجة لـ Microsoft مربع ، ثم انقر فوق OK .

4. احفظ الرمز واضغط على قديم + Q مفاتيح لإغلاق ميكروسوفت فيسوال باسيك للتطبيقات نافذة.

ملحوظة: يرجى التأكد من أن ملف تمكين كافة وحدات الماكرو تم تمكين الخيار في Outlook الخاص بك. يمكنك تحديد هذا الخيار باتباع الخطوات الموضحة أدناه.

الخطوة 2: بناء قاعدة لاستخدام البرنامج النصي

بعد إضافة برنامج VBA النصي في Outlook ، تحتاج إلى إنشاء قاعدة لاستخدام البرنامج النصي بناءً على شروط معينة.

1. انتقل إلى علامة التبويب الصفحة الرئيسية ، انقر فوق قوانيـن > إدارة القواعد والتنبيهات.

2. في ال القواعد والتنبيهات مربع الحوار، انقر فوق قانون جديد زر لإنشاء قاعدة.

نصيحة: إذا قمت بإضافة حسابات بريد إلكتروني متعددة إلى Outlook الخاص بك ، فيرجى تحديد حساب في قم بتطبيق التغييرات على هذا المجلد القائمة المنسدلة حيث تريد تطبيق القاعدة. خلاف ذلك ، سيتم تطبيقه على البريد الوارد لحساب البريد الإلكتروني المحدد حاليًا.

3. في الأول معالج القواعد مربع الحوار، حدد تطبيق القاعدة على الرسائل التي أتلقىها في ال الخطوة1 مربع، ثم انقر فوق التالي.

4. في الثانية معالج القواعد مربع الحوار ، تحتاج إلى:

4.1) حدد شرطًا واحدًا أو أكثر في الخطوة1 صندوق حسب احتياجاتك ؛
في هذه الحالة ، أرغب في طباعة المرفقات في رسائل البريد الإلكتروني الواردة من مرسل محدد فقط. هنا ، أتحقق من ملف من الناس أو المجموعة العامة مربع.
4.2) انقر فوق القيمة المسطرة في ملف الخطوة2 مربع لتحرير الشرط ؛
شنومكس) انقر التالي. انظر لقطة الشاشة:

5. في الثالث معالج القواعد مربع الحوار ، تحتاج إلى تكوين على النحو التالي.

شنومكس) في الخطوة 1: حدد قسم الإجراءات، افحص ال تشغيل البرنامج النصي صندوق؛
شنومكس) في الخطوة2 القسم ، انقر فوق النص الذي تحته خط "برنامج نصي" ؛
5.3) في الافتتاح حدد البرنامج النصي في مربع الحوار ، انقر فوق اسم رمز VBA الذي أضفته أعلاه ، ثم انقر فوق OK.
شنومكس) انقر فوق التالى زر. انظر لقطة الشاشة:

نصيحة: إذا كان "تشغيل البرنامج النصي”مفقود في ملف معالج القواعديمكنك عرضها باتباع الطريقة المذكورة في هذا المقال: استعادة المفقودين تشغيل برنامج نصي pption في قاعدة Outlook.

6. ثم آخر معالج القواعد ينبثق طلب الاستثناءات. يمكنك تحديد الاستثناءات إذا لزم الأمر ، وإلا فانقر فوق التالى زر بدون أي تحديدات。

7. في الماضي معالج القواعد، فأنت بحاجة إلى تحديد اسم للقاعدة ، ثم النقر فوق نهاية .

8. ثم يعود إلى القواعد والتنبيهات مربع الحوار ، يمكنك رؤية القاعدة التي قمت بإنشائها مدرجة في القائمة ، انقر فوق OK زر لإنهاء الإعدادات بأكملها.

من الآن فصاعدًا ، عند استلام بريد إلكتروني من الشخص المحدد ، ستتم طباعة الملفات المرفقة تلقائيًا.


مقالات ذات صلة

قم بطباعة المرفقات (المرفقات) فقط من بريد إلكتروني واحد أو رسائل بريد إلكتروني محددة في Outlook
في Outlook ، يمكنك طباعة رسائل البريد الإلكتروني ، ولكن هل قمت بطباعة المرفقات من بريد إلكتروني واحد فقط أو من رسائل بريد إلكتروني محددة في Outlook؟ يقدم هذا المقال الحيل في حل هذه الوظيفة.

فقط طباعة رأس رسالة من بريد إلكتروني في Outlook
عند طباعة رسالة بريد إلكتروني في Outlook ، ستتم طباعة كل من رأس الرسالة ونص الرسالة في البريد الإلكتروني. ومع ذلك ، في بعض الحالات الخاصة ، قد تحتاج فقط إلى طباعة رأس الرسالة بالموضوع ، والمرسل ، والمستلمين ، وما إلى ذلك. ستقدم هذه المقالة حلين للقيام بذلك.

اطبع تقويمًا في نطاق زمني محدد / مخصص في Outlook
عادةً ، عند طباعة تقويم في طريقة عرض الشهر في Outlook ، فإنه سيحدد تلقائيًا الشهر الذي يحتوي على التاريخ المحدد حاليًا. ولكن ، قد تحتاج إلى طباعة التقويم في نطاق زمني مخصص ، مثل 3 أشهر ونصف العام وما إلى ذلك. ستقدم هذه المقالة الحل المناسب لك.

طباعة جهة اتصال مع صورة في Outlook
عادةً ، لن تتم طباعة صورة جهة الاتصال عند طباعة جهة الاتصال في Outlook. لكن في بعض الأحيان ، سيكون من الأكثر إثارة للإعجاب طباعة جهة اتصال مع صورتها. ستقدم هذه المقالة بعض الحلول لإنجازها.

اطبع مجموعة مختارة من بريد إلكتروني في Outlook
إذا تلقيت رسالة بريد إلكتروني ووجدت أن هناك مجموعة مختارة من محتوى البريد الإلكتروني يجب طباعتها بدلاً من طباعة الرسالة بأكملها ، فماذا ستفعل؟ في الواقع ، يمكن أن يساعدك Outlook في تحقيق هذه العملية بمساعدة مستعرضات الإنترنت ، مثل Firefox و Internet Explorer. هنا سوف آخذ متصفحات الإنترنت على سبيل المثال. يرجى إلقاء نظرة على البرامج التعليمية التالية.

المزيد من المقالات حول "الطباعة في Outlook" ...


أفضل أدوات إنتاجية المكتب

كوتولس لتوقعات - أكثر من 100 ميزة قوية لتعزيز توقعاتك

🤖 مساعد بريد الذكاء الاصطناعي: رسائل بريد إلكتروني احترافية فورية مع سحر الذكاء الاصطناعي - بنقرة واحدة للردود العبقرية، والنغمة المثالية، وإتقان متعدد اللغات. تحويل البريد الإلكتروني دون عناء! ...

📧 أتمتة البريد الإلكتروني: خارج المكتب (متوفر لـ POP وIMAP)  /  جدولة إرسال رسائل البريد الإلكتروني  /  نسخة تلقائية/نسخة مخفية الوجهة حسب القواعد عند إرسال البريد الإلكتروني  /  إعادة التوجيه التلقائي (القواعد المتقدمة)   /  إضافة تحية تلقائية   /  تقسيم رسائل البريد الإلكتروني متعددة المستلمين تلقائيًا إلى رسائل فردية 

📨 إدارة البريد الإلكتروني: استدعاء رسائل البريد الإلكتروني بسهولة  /  حظر رسائل البريد الإلكتروني الاحتيالية حسب الموضوعات والآخرين  /  حذف رسائل البريد الإلكتروني المكررة  /  المزيد من خيارات البحث  /  توحيد المجلدات 

📁 المرفقات بروحفظ دفعة  /  فصل دفعة  /  ضغط دفعة  /  حفظ تلقائي   /  فصل تلقائي  /  ضغط تلقائي 

؟؟؟؟ واجهة ماجيك: 😊 المزيد من الرموز التعبيرية الجميلة والرائعة   /  عزز إنتاجية Outlook الخاص بك باستخدام طرق العرض المبوبة  /  تصغير Outlook بدلاً من الإغلاق 

؟؟؟؟ بنقرة واحدة عجائب: الرد على الكل بالمرفقات الواردة  /   رسائل البريد الإلكتروني لمكافحة التصيد  /  🕘إظهار المنطقة الزمنية للمرسل 

👩🏼‍🤝‍👩🏻 جهات الاتصال والتقويم: دفعة إضافة جهات الاتصال من رسائل البريد الإلكتروني المحددة  /  تقسيم مجموعة اتصال إلى مجموعات فردية  /  إزالة تذكير عيد ميلاد 

على مدى ميزات 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