More Outlook Resource Sites

Microsoft Developer Network (MSDN)

FAQs and other general resources

forum 21-Jan-2017 10:08

Looking for help with Outlook programming projects — VSTO, add-ins, VBA, custom Outlook forms, etc.? You′ve come to the right place!

NEW! >> Subscribe to this site via RSS. For more RSS options, see the complete list of feeds on our main news page.

    Page [ 1 ]  
 Basic Outlook Printer Friendly Version
Working with Outlook items, folders, recipients; dealing with security; writing event handlers
Save attachment in currently selected mail message
I have a working code to save the attachment from the currently displayed (opened) mail item. But can it be done without opening the mail item first? I would like to simply highlight the desired item in my inbox and then activate a macro to save the attachment contained in that item.

My current code is:
Sub SaveAttachment()

Dim myinspector As Outlook.Inspector
Dim myItem As Outlook.MailItem
Dim myattachments As Outlook.Attachments
Set myinspector = Application.ActiveInspector
    If Not TypeName(myinspector) = "Nothing" Then
        If TypeName(myinspector.CurrentItem) = "MailItem" Then
            Set myItem = myinspector.CurrentItem
            Set myattachments = myItem.Attachments
            myattachments.Item(1).SaveAsFile "c:\temp\test.txt"
            MsgBox "The item is of the wrong type."
        End If
    End If
End Sub

Any idea how to alter the code so that it pertains to the "highlighted"
item, not the "displayed" or "opened" item?

  12-May-2013  11:36
    Page [ 1 ]