Hoppa till huvudinnehåll

Hur listar jag alla bifogade namn i meddelandetexten när man skriver e-post i Outlook?

Finns det några bra sätt för oss att infoga alla bifogade namn i meddelandetexten när vi skriver ett e-postmeddelande i Outlook? Den här artikeln kommer jag att prata om hur man löser detta jobb i Outlook.

Lista alla bifogade namn i meddelandetexten när du skriver e-post med VBA-kod

Lista alla bifogade namn i meddelandetexten när du skriver e-post med en enkel funktion


Lista alla bifogade namn i meddelandetexten när du skriver e-post med VBA-kod

Gör med följande steg för att slutföra uppgiften:

1. Håll ner ALT + F11 nycklar för att öppna Microsoft Visual Basic för applikationer fönster.

2. I Microsoft Visual Basic för applikationer dubbelklicka ThisOutlookSession från Project1 (VbaProject.OTM) rutan för att öppna läget och sedan kopiera och klistra in följande kod i den tomma modulen.

VBA-kod: Lista alla bifogade namn i meddelandetexten:

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. Fortsätt sedan med att klicka Insert > Modulerna, kopiera och klistra in koden nedan i den öppnade tomma modulen, se skärmdump:

VBA-kod: Lista alla bifogade namn i meddelandetexten:

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. Och klicka sedan på verktyg > Referensprojekt i Microsoft Visual Basic för applikationer fönster, i poppade ut Referenser-projekt1 dialogruta, kontrollera Microsoft Word -objektbibliotek alternativ från Tillgängliga referenser listruta, se skärmdump:

5. Klicka OK för att avsluta dialogrutan bör du lägga till makroknappen i Snabbåtkomstverktygsfält. I det nya Meddelande fönster, välj Fler kommandon från Anpassa snabbåtkomstverktygsfältet rullgardinsmeny, se skärmdump:

6. I Outlook-Val dialogrutan, gör följande:

(1.) Välj Makron från Välj kommandon från rullgardinsmeny;

(2.) Klicka på makronamnet som du precis har infogat;

(3.) Och klicka sedan på Lägg till för att lägga till makrot i Anpassa snabbåtkomstverktygsfältet.

7. Klicka sedan OK för att stänga dialogrutan, nu har makroknappen infogats i Snabbåtkomstverktygsfält, se skärmdump:

8. Nu, när du skapar ett nytt meddelande och klickar på makroknappen, kommer bilagornas namn att infogas ovanför meddelandetexten enligt följande skärmdump:


Lista alla bifogade namn i meddelandetexten när du skriver e-post med en enkel funktion

Kan vara ovanstående kod är lite svårt för dig att tillämpa, om du har Kutools för Outlook, med dess Kopiera namn funktionen kan du snabbt kopiera namnen på bilagorna i ett meddelande och klistra in dem var du än behöver.

Notera:Att tillämpa detta Kopiera namnFör det första bör du ladda ner Kutools för Outlook, och använd sedan funktionen snabbt och enkelt.

När du har installerat Kutools för Outlook, gör så här:

1. Skapa först den nya e-postadressen du behöver och klicka sedan Kutools > Kopiera namn i det nya Meddelande fönster, se skärmdump:

2. Och sedan kommer en uppmaningsruta att dyka upp för att påminna dig om att bilagornas namn har kopierats till urklipp, se skärmdump:

3. Nu behöver du bara trycka Ctrl + V tangenterna tillsammans för att klistra in bilagornas namn i meddelandetexten du behöver, se skärmdump:


Fler relativa artiklar:

  • Svara alla med originalbilagor i Outlook
  • Normalt, när du använder funktionen Svara alla för att svara på meddelandet till alla mottagare i Outlook, kommer de ursprungliga bilagorna att gå förlorade automatiskt. Är det möjligt att bifoga originalbilagor när du svarar på alla i Outlook?
  • Ladda ner/spara bilagor från Outlook till en viss mapp
  • Generellt kan du spara alla bilagor i ett e-postmeddelande genom att klicka på Bilagor> Spara alla bilagor i Outlook. Men om du behöver spara alla bilagor från alla mottagna e-postmeddelanden och ta emot e-postmeddelanden, något ideal? Denna artikel introducerar två lösningar för att automatiskt ladda ner bilagor från Outlook till en viss mapp.
  • Ändra standardbilagesparande plats i Outlook
  • Har du tröttnat på att hitta den bifogade platsen du har angett varje gång när du startar Outlook? I den här handledningen visar vi dig hur du ändrar standardbilageplatsen. Därefter öppnas den angivna sparingsmappen automatiskt varje gång du sparar bilagorna även om du startar om Outlook.
  • Ta bort alla bilagor från e-post i Outlook
  • Normalt när du förhandsgranskar ett e-postmeddelande kan du ta bort en bilaga genom att högerklicka och välja alternativet Ta bort bilaga. Ibland kan det finnas många bilagor i ett e-postmeddelande, och det kommer att vara tråkigt att ta bort dem en efter en. Här ordnar vi dig med två enkla knep för att ta bort alla bilagor i ett e-postmeddelande, och ta bort alla bilagor från flera e-postmeddelanden också i Outlook.

Bästa kontorsproduktivitetsverktyg

Kutools för Outlook - Över 100 kraftfulla funktioner för att överladda din Outlook

🤖 AI Mail Assistant: Instant proffs-e-postmeddelanden med AI-magi – ett klick för geniala svar, perfekt ton, flerspråkig behärskning. Förvandla e-post utan ansträngning! ...

📧 Email Automation: Frånvaro (tillgänglig för POP och IMAP)  /  Schemalägg Skicka e-post  /  Auto CC/BCC enligt regler när du skickar e-post  /  Automatisk vidarebefordran (avancerade regler)   /  Lägg automatiskt till hälsning   /  Dela automatiskt e-postmeddelanden med flera mottagare i individuella meddelanden ...

📨 Email Management: Hämta enkelt e-postmeddelanden  /  Blockera bluff-e-postmeddelanden av ämnen och andra  /  Ta bort duplicerade e-postmeddelanden  /  Avancerad Sökning  /  Konsolidera mappar ...

📁 Bilagor ProBatch Spara  /  Batch lossa  /  Batchkomprimera  /  Automatisk sparning   /  Auto Lossa  /  Automatisk komprimering ...

🌟 Gränssnittsmagi: 😊 Fler vackra och coola emojis   /  Öka din Outlook-produktivitet med flikar  /  Minimera Outlook istället för att stänga ...

👍 Underverk med ett klick: Svara alla med inkommande bilagor  /   E-postmeddelanden mot nätfiske  /  🕘Visa avsändarens tidszon ...

👩🏼‍🤝‍👩🏻 Kontakter och kalender: Lägg till kontakter i grupp från valda e-postmeddelanden  /  Dela upp en kontaktgrupp till individuella grupper  /  Ta bort påminnelser om födelsedag ...

Över 100 funktioner Vänta på din utforskning! Klicka här för att upptäcka mer.

Läs mer       Gratis nedladdning      Inköp
 

 

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