Macro to get name of attachments in a message

W

Wilfried

JJ said:
Hi,
Has anyone got a sample macro to do this?

Here we are (extracted from my macro for saving attachments to disk and
removing them from the message):

Sub Attachments()
Dim myOlApp As Outlook.Application
Dim myInspector As Outlook.Inspector
Dim myItem As Outlook.MailItem
Dim myAttachments As Outlook.Attachments
'
Set myOlApp = CreateObject("Outlook.Application")
Set myInspector = myOlApp.ActiveInspector
If Not TypeName(myInspector) = "Nothing" Then
If TypeName(myInspector.CurrentItem) = "MailItem" Then
Set myItem = myInspector.CurrentItem
Set myAttachments = myItem.Attachments
If myAttachments.Count > 0 Then
For i = myAttachments.Count To 1 Step -1
MsgBox "Name of attachment is " & _
myAttachments.Item(i).DisplayName
Next i
End If
Else
MsgBox "The current selection is no message."
End If
End If
'free variables
Set myOlApp = Nothing
Set myInspector = Nothing
Set myItem = Nothing
Set myAttachments = Nothing
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top