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

Outlookで電子メールを作成するときに、すべての添付ファイル名をメッセージ本文に一覧表示するにはどうすればよいですか?

Outlookで電子メールを作成するときに、すべての添付ファイル名をメッセージ本文に挿入するための良い方法はありますか? この記事では、Outlookでこのジョブを解決する方法について説明します。

VBAコードを使用して電子メールを作成するときに、すべての添付ファイル名をメッセージ本文にリストします

簡単な機能でメールを作成するときに、すべての添付ファイル名をメッセージ本文にリストします


VBAコードを使用して電子メールを作成するときに、すべての添付ファイル名をメッセージ本文にリストします

このタスクを完了するには、次の手順を実行してください。

1。 を押し続けます Alt + F11 キーを押して アプリケーション向け Microsoft Visual Basic 窓。

2。 の中に アプリケーション向け Microsoft Visual Basic ウィンドウ、ダブルクリック このOutlookSession Project1(VbaProject.OTM) ペインでモードを開き、次のコードをコピーして空のモジュールに貼り付けます。

VBAコード:すべての添付ファイル名をメッセージ本文にリストします。

Private Sub Application_ItemSend(ByVal Item As Object, Cancel As Boolean)
    Dim xMailItem As MailItem
    If Item.Class = olMail Then
        Set xMailItem = Item
        If xMailItem.Attachments.Count > 0 Then
          AddAttachmentNamesToBody
        End If
    End If
    End Sub

3。 次にクリックします インセット > モジュール、以下のコードをコピーして、開いた空白のモジュールに貼り付けます。スクリーンショットを参照してください。

VBAコード:すべての添付ファイル名をメッセージ本文にリストします。

Public Sub AddAttachmentNamesToBody()
    Dim xMailItem As MailItem
    Dim xAttachment As Attachment
    Dim xFileName As String
   Dim xInspector As Outlook.Inspector
    Dim xDoc As Word.Document
    Dim xWdSelection As Word.Selection
    On Error Resume Next
    Set xMailItem = Outlook.ActiveInspector.CurrentItem
    If xMailItem.Attachments.Count = 0 Then
        Exit Sub
    End If
    xFileName = ""
    For Each xAttachment In xMailItem.Attachments
        If xFileName = "" Then
            xFileName = " <" & xAttachment.FileName & "> "
        Else
            xFileName = xFileName & vbCrLf & " <" & xAttachment.FileName & "> "
        End If
    Next xAttachment
    Set xInspector = Outlook.Application.ActiveInspector()
    Set xDoc = xInspector.WordEditor
    Set xWdSelection = xDoc.Application.Selection
    xWdSelection.HomeKey Unit:=wdStory
    xWdSelection.InsertBefore "Attachments: " & vbCrLf & xFileName & vbCrLf & vbCrLf
    Set xMailItem = Nothing
    End Sub

4。 そして、 ツール > 参考文献 セクションに アプリケーション向け Microsoft Visual Basic 飛び出した窓 参考資料-Project1 ダイアログボックス、チェック MicrosoftWordオブジェクトライブラリ オプションから 利用可能な参考文献 リストボックス、スクリーンショットを参照:

5に設定します。 OK をクリックします。 OK ダイアログ ボックスを終了するには、マクロ ボタンを クイックアクセスツールバー。 新しい メッセージ ウィンドウ、選択 その他のコマンド クイックアクセスツールバーをカスタマイズする ドロップダウン、スクリーンショットを参照してください:

6。 の中に Outlookのオプション ダイアログボックスで、次の操作を実行します。

(1.)選択 マクロ からのコマンドを選択 ドロップダウンリスト;

(2.) 今挿入したマクロ名をクリックします。

(3.)次にクリック Add ボタンをクリックしてマクロを追加します クイックアクセスツールバーをカスタマイズする.

7。 次に、をクリックします OK ダイアログ ボックスを閉じるには、マクロ ボタンが クイックアクセスツールバー、スクリーンショットを参照してください:

8。 ここで、新しいメッセージを作成し、マクロ ボタンをクリックすると、次のスクリーンショットに示すように、添付ファイル名がメッセージ本文の上に挿入されます。


簡単な機能でメールを作成するときに、すべての添付ファイル名をメッセージ本文にリストします

上記のコードは、適用するのが少し難しいかもしれません。 Kutools for Outlookそのと 名前をコピーする この機能を使用すると、メッセージの添付ファイル名をすばやくコピーし、必要な場所に貼り付けることができます。

注:これを適用する 名前をコピーする、まず、ダウンロードする必要があります Kutools for Outlook、次に機能をすばやく簡単に適用します。

インストールした後 Kutools for Outlook、次のようにしてください。

1。 まず、必要な新しいメールを作成し、クリックしてください クツール > 名前をコピーする 新しい メッセージ ウィンドウ、スクリーンショットを参照してください:

2。 次に、添付ファイル名がクリップボードにコピーされたことを通知するプロンプト ボックスが表示されます。スクリーンショットを参照してください。

3。 あとは、 を押すだけです Ctrlキー+ V キーを一緒に押して、添付ファイル名を必要なメッセージ本文に貼り付けます。スクリーンショットを参照してください。


より相対的な記事:

  • Outlook で元の添付ファイルを付けて全員に返信する
  • 通常、[すべて返信]機能を適用してOutlookのすべての受信者にメッセージを返信すると、元の添付ファイルは自動的に失われます。 Outlookで全員に返信するときに、元の添付ファイルを添付することはできますか?
  • Outlook から添付ファイルを特定のフォルダーにダウンロード/保存する
  • 一般的に、Outlookで[添付ファイル]> [すべての添付ファイルを保存]をクリックすると、XNUMXつの電子メールのすべての添付ファイルを保存できます。 しかし、受信したすべての電子メールと受信した電子メールのすべての添付ファイルを保存する必要がある場合、理想的なものはありますか? この記事では、Outlookから特定のフォルダーに添付ファイルを自動的にダウンロードするXNUMXつのソリューションを紹介します。
  • Outlookでデフォルトの添付ファイルの保存場所を変更する
  • Outlookを起動するたびに、指定した添付ファイルの場所を見つけることにうんざりしていませんか? このチュートリアルでは、デフォルトの添付ファイルの場所を変更する方法を示します。 その後、Outlookを再起動しても、添付ファイルを保存するたびに、指定した添付ファイル保存フォルダが自動的に開きます。
  • Outlook で電子メールからすべての添付ファイルを削除する
  • 通常、電子メールをプレビューしているときに、右クリックして [添付ファイルの削除] 項目を選択すると、添付ファイルを削除できます。 電子メール メッセージに多数の添付ファイルが含まれる場合があり、それらを XNUMX つずつ削除するのは面倒です。 ここでは、XNUMX つのメール内のすべての添付ファイルを削除する方法と、Outlook で同様に複数のメールからすべての添付ファイルを削除するための XNUMX つの簡単なテクニックを紹介します。

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

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

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

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

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

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

🌟 インターフェースマジック: 😊もっと可愛くてクールな絵文字   /  タブ付きビューで Outlook の生産性を向上  /  Outlook を閉じる代わりに最小化する ...

???? ワンクリックの驚異: 受信した添付ファイルをすべてに返信する  /   フィッシングメール対策  /  🕘送信者のタイムゾーンを表示 ...

👩🏼‍🤝‍👩🏻 連絡先とカレンダー: 選択したメールから連絡先を一括追加  /  連絡先グループを個別のグループに分割する  /  誕生日のリマインダーを削除する ...

オーバー 100の特長 あなたの探索をお待ちしています! ここをクリックして詳細をご覧ください。

 

 

Comments (12)
No ratings yet. Be the first to rate!
This comment was minimized by the moderator on the site
Why am I getting "user-defined type not defined" when I get to Step 8?
This comment was minimized by the moderator on the site
Why am I getting "user-defined type not defined" when I get to Step 8?
This comment was minimized by the moderator on the site
When I do this, it always put the attachments at the beginning of the message, no matter where my cursor is located. I then have to copy/paste to the bottom of the email. Is there a way to change that?
This comment was minimized by the moderator on the site
Hello, VMS,
If you want to put the attachments at the the position of your cursor, please replace the second code with following code:

Public Sub AddAttachmentNamesToBody()

Dim xMailItem As MailItem

Dim xAttachment As Attachment

Dim xFileName As String

Dim xInspector As Outlook.Inspector

Dim xDoc As Word.Document

Dim xWdSelection As Word.Selection

On Error Resume Next

Set xMailItem = Outlook.ActiveInspector.CurrentItem

If xMailItem.Attachments.Count = 0 Then

Exit Sub

End If

xFileName = ""

For Each xAttachment In xMailItem.Attachments

If xFileName = "" Then

xFileName = " <" & xAttachment.FileName & "> "

Else

xFileName = xFileName & vbCrLf & " <" & xAttachment.FileName & "> "

End If

Next xAttachment

Set xInspector = Outlook.Application.ActiveInspector()

Set xDoc = xInspector.WordEditor

Set xWdSelection = xDoc.Application.Selection

xWdSelection.InsertBefore "Attachments: " & vbCrLf & xFileName & vbCrLf & vbCrLf

Set xMailItem = Nothing

End Sub

Please try, hope it can help you!
This comment was minimized by the moderator on the site
That worked! Now another favor... How do I exclude certain file types or names? My required company signature contains a PNG file that I would like to exclude.Thank you!!
This comment was minimized by the moderator on the site
To exclude some specific files, please apply the below code, please try it.
Public Sub AddAttachmentNamesToBody()

Dim xMailItem As MailItem

Dim xAttachment As Attachment

Dim xFileName As String

Dim xInspector As Outlook.Inspector

Dim xDoc As Word.Document

Dim xWdSelection As Word.Selection

Dim xExt As String

Dim xFound As Boolean

Dim xExtArr As Variant

On Error Resume Next

xExtArr = Array("docx", "exe") 'change the file extension you want to exclude

Set xMailItem = Outlook.ActiveInspector.CurrentItem

If xMailItem.Attachments.Count = 0 Then

Exit Sub

End If

xFileName = ""

For Each xAttachment In xMailItem.Attachments

xExt = VBA.Mid(xAttachment.FileName, VBA.InStrRev(xAttachment.FileName, ".") + 1)

xFound = False

For i = LBound(xExtArr) To UBound(xExtArr)

If xExt = xExtArr(i) Then

xFound = True

Exit For

End If

Next

If xFound = False Then

If xFileName = "" Then

xFileName = " <" & xAttachment.FileName & "> "

Else

xFileName = xFileName & vbCrLf & " <" & xAttachment.FileName & "> "

End If

End If

Next xAttachment

Set xInspector = Outlook.Application.ActiveInspector()

Set xDoc = xInspector.WordEditor

Set xWdSelection = xDoc.Application.Selection

xWdSelection.InsertBefore "Attachments: " & vbCrLf & xFileName & vbCrLf & vbCrLf

Set xMailItem = Nothing

End Sub
This comment was minimized by the moderator on the site
when I tried this code it sends the attachment names in every email that has attachments.
I want it to only do it when I click the macro.

How do I amend the code to do just that?
This comment was minimized by the moderator on the site
I also don't know how to fix it. Anyone could hep on that?
This comment was minimized by the moderator on the site
This is wonderful -- thank you! Is there also a way to somehow view all the attachment names in an email that has been sent to you from someone else (i.e. received)? For some reason, the file names are not displaying in full unless you hover, which is ridiculous when you regularly have 15 files to sort through.
This comment was minimized by the moderator on the site
Hello,
To List all attachment names in an received email, please copy and pase the below VBA code into the ThisOutlookSession module of the Microsoft Visual Basic for Applications window:

Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
Dim xEIDArr As Variant, xEID As Variant, xItem As Object
Dim xAttachment As Attachment
Dim xFileName As String
On Error Resume Next
xEIDArr = Split(EntryIDCollection, ",")
For Each xEID In xEIDArr
Set xItem = Session.GetItemFromID(xEID)
If xItem.Class = olMail Then
xFileName = ""
For Each xAttachment In xItem.Attachments
If IsEmbeddedAttachment(xAttachment) = False Then
If xFileName = "" Then
xFileName = " " & "<" & xAttachment.FileName & ">"
Else
xFileName = xFileName & "
" & " " & "<" & xAttachment.FileName & ">"
End If
End If
Next xAttachment
If xFileName = "" Then Exit Sub
xFileName = "Attachments: " & "
" & xFileName & "
" & "
"
xItem.HTMLBody = "" & xFileName & "" & xItem.HTMLBody
xItem.Save
End If
Next
Set xItem = Nothing
End Sub

Function IsEmbeddedAttachment(Attach As Attachment)
Dim xAttParent As Object
Dim xCID As String, xID As String
Dim xHTML As String
On Error Resume Next
Set xAttParent = Attach.Parent
xCID = ""
xCID = Attach.PropertyAccessor.GetProperty("http://schemas.microsoft.com/mapi/proptag/0x3712001F")
If xCID <> "" Then
xHTML = xAttParent.HTMLBody
xID = "cid:" & xCID
If InStr(xHTML, xID) > 0 Then
IsEmbeddedAttachment = True
Else
IsEmbeddedAttachment = False
End If
End If
End Function

After pasting this code, when new emails with attachments arriving in your Outlook, the attachment names will be listed at the top of the message body automatically.
Please try it, hope it can help you!
This comment was minimized by the moderator on the site
this is great. Is there any way to merge this with VMS's request above to exclude some specific files included in signatures (.png, .jpg, etc.)?
This comment was minimized by the moderator on the site
Great, thanks for that. I wonder if it is possible that the list of attachments is only attached when I write to a specific email address?
There are no comments posted here yet
Please leave your comments in English
Posting as Guest
×
Rate this post:
0   Characters
Suggested Locations