Vai al contenuto principale

Come elencare tutti i nomi degli allegati nel corpo del messaggio durante la composizione della posta elettronica in Outlook?

Esistono buoni modi per inserire tutti i nomi degli allegati nel corpo del messaggio durante la composizione di un'e-mail in Outlook? In questo articolo, parlerò di come risolvere questo lavoro in Outlook.

Elenca tutti i nomi degli allegati nel corpo del messaggio durante la composizione di e-mail con codice VBA

Elenca tutti i nomi degli allegati nel corpo del messaggio durante la composizione dell'email con una semplice funzionalità


Elenca tutti i nomi degli allegati nel corpo del messaggio durante la composizione di e-mail con codice VBA

Si prega di eseguire i seguenti passaggi per completare questa attività:

1. Tieni premuto il ALT + F11 chiavi per aprire il Microsoft Visual Basic, Applications Edition finestra.

2. Nel Microsoft Visual Basic, Applications Edition finestra, fare doppio clic Questa sessione di Outlook dal Progetto1 (VbaProject.OTM) riquadro per aprire la modalità, quindi copia e incolla il codice seguente nel modulo vuoto.

Codice VBA: elenca tutti i nomi degli allegati nel corpo del messaggio:

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. Quindi continua a fare clic inserire > Moduli, copia e incolla sotto il codice nel modulo vuoto aperto, vedi screenshot:

Codice VBA: elenca tutti i nomi degli allegati nel corpo del messaggio:

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. E poi clicca Strumenti > Riferimenti nel Microsoft Visual Basic, Applications Edition finestra, nel saltato fuori Riferimenti-Progetto1 finestra di dialogo, controllare Libreria di oggetti di Microsoft Word opzione dal Riferimenti disponibili casella di riepilogo, vedi screenshot:

5. Clic OK per uscire dalla finestra di dialogo, è necessario aggiungere il pulsante macro nel file Barra degli strumenti di accesso rapido. Nel nuovo Messaggio finestra, scegliere Altri comandi dal Personalizza la barra degli strumenti di accesso rapido menu a discesa, vedi screenshot:

6. Nel Opzioni di Outlook finestra di dialogo, eseguire le seguenti operazioni:

(1.) Seleziona Macro dal Scegli comandi da menu `A tendina;

(2.) Fare clic sul nome della macro che hai appena inserito;

(3.) E quindi fare clic su Aggiungi pulsante per aggiungere la macro nel file Personalizza la barra degli strumenti di accesso rapido.

7. Quindi fare clic OK per chiudere la finestra di dialogo, ora, il pulsante macro è stato inserito nel file Barra degli strumenti di accesso rapido, vedi screenshot:

8. Ora, quando crei un nuovo messaggio e fai clic sul pulsante della macro, i nomi degli allegati verranno inseriti sopra il corpo del messaggio come mostrato nella seguente schermata:


Elenca tutti i nomi degli allegati nel corpo del messaggio durante la composizione dell'email con una semplice funzionalità

Può essere che il codice sopra sia così difficile da applicare, se lo hai fatto Kutools for Outlook, Con la sua Copia nomi è possibile copiare rapidamente i nomi degli allegati di un messaggio e incollarli ovunque sia necessario.

Nota:Per applicare questo Copia nomi, in primo luogo, dovresti scaricare il file Kutools for Outlooke quindi applica la funzione in modo rapido e semplice.

Dopo l'installazione Kutools for Outlook, per favore fai come questo:

1. Innanzitutto, crea la nuova email di cui hai bisogno, quindi fai clic su Kutools > Copia nomi nel nuovo Messaggio finestra, vedi screenshot:

2. E poi, verrà visualizzata una finestra di messaggio per ricordarti che i nomi degli allegati sono stati copiati negli appunti, vedi screenshot:

3. Ora, devi solo premere Ctrl + V tasti insieme per incollare i nomi degli allegati nel corpo del messaggio di cui hai bisogno, vedi screenshot:


Articoli più relativi:

  • Rispondi a tutti con allegati originali in Outlook
  • Normalmente, quando si applica la funzione Rispondi a tutti per rispondere al messaggio a tutti i destinatari in Outlook, gli allegati originali verranno persi automaticamente. È possibile allegare allegati originali quando si risponde a tutti in Outlook?
  • Scarica / Salva allegati da Outlook in una determinata cartella
  • In generale, puoi salvare tutti gli allegati di un'e-mail facendo clic su Allegati> Salva tutti gli allegati in Outlook. Ma se è necessario salvare tutti gli allegati da tutte le e-mail ricevute e ricevute, qualsiasi ideale? Questo articolo introdurrà due soluzioni per scaricare automaticamente gli allegati da Outlook in una determinata cartella.
  • Modifica la posizione di salvataggio degli allegati predefiniti in Outlook
  • Sei stufo di trovare la posizione degli allegati che hai specificato ogni volta che avvii Outlook? In questo tutorial, ti mostreremo come modificare la posizione predefinita degli allegati. Dopodiché, la cartella di salvataggio degli allegati specificata verrà aperta automaticamente ogni volta che salvi gli allegati anche se riavvii Outlook.
  • Rimuovi tutti gli allegati dall'e-mail in Outlook
  • Normalmente quando si visualizza l'anteprima di un'e-mail, è possibile eliminare un allegato facendo clic con il tasto destro e selezionare l'elemento Rimuovi allegato. A volte possono esserci molti allegati in un messaggio di posta elettronica e sarà noioso rimuoverli uno per uno. Qui ti organizziamo con due semplici trucchi per rimuovere tutti gli allegati in un'unica e-mail e rimuovere tutti gli allegati da più e-mail anche in Outlook.

I migliori strumenti per la produttività in ufficio

Kutools for Outlook - Oltre 100 potenti funzionalità per potenziare il tuo Outlook

🤖 Assistente di posta AI: E-mail istantanee professionali con la magia dell'intelligenza artificiale: risposte geniali con un solo clic, tono perfetto, padronanza multilingue. Trasforma l'e-mail senza sforzo! ...

???? Automazione di posta elettronica: Fuori sede (disponibile per POP e IMAP)  /  Pianifica l'invio di e-mail  /  CC/BCC automatico in base alle regole durante l'invio di e-mail  /  Inoltro automatico (regole avanzate)   /  Aggiunta automatica di saluto   /  Suddividi automaticamente le email con più destinatari in singoli messaggi ...

📨 gestione e-mail: Richiama facilmente le email  /  Blocca le email truffe per soggetto e altri  /  Elimina email duplicate  /  Ricerca avanzata  /  Consolidare cartelle ...

📁 Allegati ProSalvataggio in batch  /  Stacca batch  /  Comprimi in lotti  /  Salvataggio automatico   /  Scollegamento automatico  /  Comprimi automaticamente ...

🌟 Magia dell'interfaccia: 😊Più emoji carini e fantastici   /  Aumenta la tua produttività in Outlook con le visualizzazioni a schede  /  Riduci a icona Outlook invece di chiuderlo ...

👍 Meraviglie con un clic: Rispondi a tutti con gli allegati in arrivo  /   E-mail anti-phishing  /  🕘Mostra il fuso orario del mittente ...

👩🏼‍🤝‍👩🏻 Contatti e calendario: Aggiungi in batch contatti dalle email selezionate  /  Dividere un gruppo di contatti in singoli gruppi  /  Rimuovi promemoria compleanno ...

Al di sopra Caratteristiche 100 Attendi la tua esplorazione! Clicca qui per scoprire di più.

 

 

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