メインコンテンツへスキップ

電子メールがOutlookに到着したときに添付ファイルを自動的に印刷するにはどうすればよいですか?

このチュートリアルでは、VBAスクリプトとOutlookルールを組み合わせて、特定の電子メールがOutlookに到着したときにその添付ファイルを自動的に印刷できるようにする方法を示します。


特定のメールが届いたときに添付ファイルを自動的に印刷する

特定の送信者からの受信メールの添付ファイルを自動的に印刷するとします。 あなたはそれを成し遂げるために次のようにすることができます。

ステップ1:Outlookでスクリプトを作成する

まず、OutlookでVBAスクリプトを作成する必要があります。

1. Outlookを起動し、を押します 他の + F11 キーを同時に開いて アプリケーション向け Microsoft Visual Basic 窓。

2。 の中に アプリケーション向け Microsoft Visual Basic ウィンドウ、ダブルクリック Project1 > MicrosoftOutlookオブジェクト > この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

ノート:

1. この VBA コードを適用して受信メールの PDF ファイルのみを印刷する前に、まずダウンロードしてインストールする必要があります。 Adobe Acrobat Readerが コンピューターのデフォルトの PDF リーダーとして設定します。
2. ラインで ケース「pdf」、 変更してください 「pdf」 印刷するファイル拡張子に。

3.先に進み、クリックします ツール > 参考文献。 ポップアップで 参照– Project1 ダイアログボックスで Microsoftスクリプトランタイム ボックスをクリックし、 OK

4.コードを保存して、 他の + Q を閉じるためのキー アプリケーション向け Microsoft Visual Basic 窓。

注: 確認してください すべてのマクロを有効にする Outlookでオプションが有効になっています。 このオプションは、以下の手順で確認できます。

ステップ2:スクリプトを使用するルールを作成する

OutlookでVBAスクリプトを追加した後、特定の条件に基づいてスクリプトを使用するためのルールを作成する必要があります。

1. [ホーム]タブに移動し、[ キャンペーンのルール > ルールとアラートを管理する.

2。 の中に ルールとアラート ダイアログボックスで 新しいルール ルールを作成するためのボタン。

ヒント: Outlookに複数の電子メールアカウントを追加した場合は、でアカウントを指定してください このフォルダに変更を適用します ルールを適用するドロップダウンリスト。 それ以外の場合は、現在選択されているメールアカウントの受信トレイに適用されます。

3.最初に ルールウィザード ダイアログボックスで 受け取ったメッセージにルールを適用する セクションに ステップ 1 ボックスをクリックし、次にクリックします。 次へ。

4番目に ルールウィザード ダイアログボックスでは、次のことを行う必要があります。

4.1)でXNUMXつ以上の条件を指定します ステップ 1 必要に応じてボックス;
この場合、指定した送信者からの受信メールの添付ファイルのみを印刷したいと思います。 ここで、私はチェックします 人や公共のグループから ボックス。
4.2)下線付きの値をクリックします ステップ 2 条件を編集するためのボックス。
4.3)をクリック 次へ。 スクリーンショットを参照してください:

5番目に ルールウィザード ダイアログボックスでは、次のように構成する必要があります。

5.1) ステップ1:アクションセクションを選択しますスクリプトを実行する ボックス;
5.2) ステップ 2 セクションで、下線付きのテキスト「スクリプト」をクリックします。
5.3)オープニングで スクリプトを選択 ダイアログボックスで、上で追加したVBAコードの名前をクリックし、[ OK;
5.4)をクリックします Next ボタン。 スクリーンショットを参照してください:

ヒント:スクリプトを実行する」オプションがありません ルールウィザード、この記事に記載されている方法に従って表示できます。 Outlookルールで欠落しているスクリプトの実行オプションを復元します.

6.次に別の ルールウィザード 例外を要求するポップアップが表示されます。 必要に応じて例外を選択できます。それ以外の場合は、[ Next 選択なしのボタン。

7.最後に ルールウィザード、ルールの名前を指定してから、をクリックする必要があります。 終了

8.次に、に戻ります。 ルールとアラート ダイアログボックスで、作成したルールがリストされているのを確認できます。 OK ボタンをクリックして、設定全体を終了します。

今後、指定者からのメールを受信すると、添付ファイルが自動で印刷されます。


関連記事

OutlookでXNUMXつの電子メールまたは選択した電子メールからの添付ファイルのみを印刷する
Outlookでは、電子メールを印刷できますが、添付ファイルをXNUMXつの電子メールまたはOutlookで選択した電子メールからのみ印刷しましたか? この記事では、この仕事を解決するための秘訣を紹介します。

Outlookで電子メールのメッセージヘッダーのみを印刷する
Outlookで電子メールを印刷すると、電子メールのメッセージヘッダーとメッセージ本文の両方が印刷されます。 ただし、特殊なケースでは、件名、送信者、受信者などを含むメッセージヘッダーを印刷する必要がある場合があります。この記事では、そのためのXNUMXつの解決策を紹介します。

Outlookで指定された/カスタムの日付範囲でカレンダーを印刷する
通常、Outlookの月表示でカレンダーを印刷すると、現在選択されている日付を含む月が自動的に選択されます。 ただし、3か月、半年などのカスタムの日付範囲内でカレンダーを印刷する必要がある場合があります。この記事では、ソリューションを紹介します。

Outlookで写真付きの連絡先を印刷する
通常、Outlookで連絡先を印刷するときに、連絡先の画像は印刷されません。 しかし、時には、その写真との連絡先を印刷する方が印象的です。 この記事では、それを実行するためのいくつかの回避策を紹介します。

Outlookで電子メールの選択を印刷する
電子メールメッセージを受信し、メッセージ全体を印刷するのではなく、選択した電子メールコンテンツを印刷する必要があることがわかった場合、どうしますか? 実際、Outlookは、FirefoxやInternetExplorerなどのインターネットブラウザを使用してこの操作を実行するのに役立ちます。 ここでは、インターネットブラウザを例にとってみましょう。 次のチュートリアルをご覧ください。

「Outlookでの印刷」に関するその他の記事...


最高のオフィス生産性向上ツール

Outlook用Kutools - Outlook を強化する 100 以上の強力な機能

🤖 AIメールアシスタント: AI の魔法を備えたインスタント プロのメール - ワンクリックで天才的な返信、完璧な口調、多言語の習得。メールを簡単に変革しましょう! ...

📧 自動メール: 不在時 (POP および IMAP で利用可能)  /  メール送信のスケジュール設定  /  メール送信時のルールによる自動CC/BCC  /  自動転送 (高度なルール)   /  あいさつを自動追加   /  複数受信者の電子メールを個別のメッセージに自動的に分割する ...

📨 電子メール管理: メールを簡単に思い出す  /  件名などで詐欺メールをブロック  /  重複するメールを削除する  /  高度な検索  /  フォルダーを統合する ...

📁 アタッチメント プロバッチ保存  /  バッチデタッチ  /  バッチ圧縮  /  自動保存   /  自動デタッチ  /  自動圧縮 ...

🌟 インターフェースマジック: 😊もっと可愛くてクールな絵文字   /  タブ付きビューで 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