Ir para o conteúdo principal

Como listar todos os nomes de anexo no corpo da mensagem ao redigir e-mail no Outlook?

Existem boas maneiras de inserirmos todos os nomes de anexo no corpo da mensagem ao redigir um e-mail no Outlook? Neste artigo, falarei sobre como resolver esse trabalho no Outlook.

Liste todos os nomes de anexo no corpo da mensagem ao redigir e-mail com código VBA

Liste todos os nomes de anexo no corpo da mensagem ao escrever e-mail com um recurso simples


Liste todos os nomes de anexo no corpo da mensagem ao redigir e-mail com código VBA

Execute as seguintes etapas para concluir esta tarefa:

1. Segure o ALT + F11 chaves para abrir o Microsoft Visual Basic para Aplicações janela.

2. No Microsoft Visual Basic para Aplicações janela, clique duplo Esta sessão do Outlook do Projeto1 (VbaProject.OTM) painel para abrir o modo e, em seguida, copie e cole o código a seguir no módulo em branco.

Código VBA: liste todos os nomes de anexo no corpo da mensagem:

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. Então continue clicando inserção > Módulo, copie e cole o código abaixo no módulo em branco aberto, veja a captura de tela:

Código VBA: liste todos os nomes de anexo no corpo da mensagem:

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, em seguida, clique em Ferramentas > Referências no Microsoft Visual Basic para Aplicações janela, no estalou para fora Referências-Projeto1 caixa de diálogo, verifique Biblioteca de objetos do Microsoft Word opção do Referências Disponíveis caixa de lista, veja a captura de tela:

5. Clique OK para sair da caixa de diálogo, então você deve adicionar o botão de macro no Barra de Ferramentas de Acesso Rápido. No novo Mensagem janela, escolha Mais comandos do Personalize a barra de ferramentas de acesso rápido drop down, veja a captura de tela:

6. No Opções do Outlook caixa de diálogo, faça as seguintes operações:

(1.) Selecione Macros do Escolha comandos de lista suspensa;

(2.) Clique no nome da macro que você inseriu agora;

(3.) Em seguida, clique em Adicionar botão para adicionar a macro ao Personalize a barra de ferramentas de acesso rápido.

7. Então clique OK para fechar a caixa de diálogo, agora, o botão de macro foi inserido no Barra de Ferramentas de Acesso Rápido, veja a captura de tela:

8. Agora, ao criar uma nova mensagem e clicar no botão de macro, os nomes dos anexos serão inseridos acima do corpo da mensagem, conforme mostrado a seguir:


Liste todos os nomes de anexo no corpo da mensagem ao escrever e-mail com um recurso simples

Pode ser que o código acima seja tão difícil para você aplicar, se você tiver Kutools for Outlook, Com o seu Copiar nomes recurso, você pode copiar rapidamente os nomes dos anexos de uma mensagem e colá-los em qualquer lugar que precisar.

Observação:Para aplicar isso Copiar nomes, em primeiro lugar, você deve baixar o Kutools for Outlooke, em seguida, aplique o recurso de forma rápida e fácil.

Depois de instalar Kutools for Outlook, por favor, faça o seguinte:

1. Primeiro, crie o novo e-mail de que precisa e clique em Kutools > Copiar nomes no novo Mensagem janela, veja a imagem:

2. E então, uma caixa de prompt aparecerá para lembrá-lo de que os nomes dos anexos foram copiados para a área de transferência, veja a captura de tela:

3. Agora, você só precisa pressionar Ctrl + V juntas para colar os nomes dos anexos no corpo da mensagem de que você precisa, consulte a captura de tela:


Mais artigos relativos:

  • Responder a todos com anexos originais no Outlook
  • Normalmente, quando você aplica a função Responder a Todos para responder a mensagem a todos os destinatários no Outlook, os anexos originais serão perdidos automaticamente. É possível anexar anexos originais ao responder a todos no Outlook?
  • Baixar / salvar anexos do Outlook para uma determinada pasta
  • De um modo geral, você pode salvar todos os anexos de um e-mail clicando em Anexos> Salvar todos os anexos no Outlook. Mas, se precisar salvar todos os anexos de todos os emails recebidos e recebidos, algum ideal? Este artigo apresentará duas soluções para baixar automaticamente anexos do Outlook para uma determinada pasta.
  • Alterar o local de salvamento do anexo padrão no Outlook
  • Você já se cansou de encontrar o local do anexo especificado sempre que inicia o Outlook? Neste tutorial, mostraremos como alterar o local padrão do anexo. Depois disso, a pasta especificada para salvar anexos será aberta automaticamente sempre que você salvar os anexos, embora reinicie o Outlook.
  • Remover todos os anexos do e-mail no Outlook
  • Normalmente, ao visualizar um e-mail, você pode excluir um anexo clicando com o botão direito e selecionar o item Remover anexo. Às vezes, pode haver muitos anexos em uma mensagem de e-mail e será tedioso removê-los um por um. Aqui nós organizamos você com dois truques fáceis para remover todos os anexos em um e-mail e remover todos os anexos de vários e-mails também no Outlook.

Melhores ferramentas de produtividade de escritório

Kutools for Outlook - Mais de 100 recursos poderosos para turbinar seu Outlook

🤖 Assistente de correio AI: E-mails profissionais instantâneos com magia de IA – um clique para respostas geniais, tom perfeito, domínio multilíngue. Transforme o envio de e-mails sem esforço! ...

📧 Automação de e-mail: Fora do escritório (disponível para POP e IMAP)  /  Agendar envio de e-mails  /  CC/BCC automático por regras ao enviar e-mail  /  Encaminhamento automático (regras avançadas)   /  Adicionar saudação automaticamente   /  Divida automaticamente e-mails de vários destinatários em mensagens individuais ...

📨 Gestão de E-mail: Lembre-se facilmente de e-mails  /  Bloquear e-mails fraudulentos por assuntos e outros  /  Apagar Emails Duplicados  /  Pesquisa Avançada  /  Consolidar pastas ...

📁 Anexos PróSalvar em lote  /  Desanexar lote  /  Comprimir em Lote  /  Salvamento automático   /  Desanexação Automática  /  Compressão automática ...

???? Interface Mágica: 😊Mais emojis bonitos e legais   /  Aumente a produtividade do seu Outlook com visualizações com guias  /  Minimize o Outlook em vez de fechar ...

???? Maravilhas com um clique: Responder a todos com anexos recebidos  /   E-mails antiphishing  /  🕘Mostrar fuso horário do remetente ...

👩🏼‍🤝‍👩🏻 Contatos e calendário: Adicionar contatos em lote de e-mails selecionados  /  Dividir um grupo de contatos em grupos individuais  /  Remover lembretes de aniversário ...

Sobre Características 100 Aguarde sua exploração! Clique aqui para descobrir mais.

 

 

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