Outlook 2003 - Reply with Attachments

1. Go to Tools > Macros > Visual Basic Editor
2. Create a new Module
3. Paste the following code:
Const TemporaryFolder = 2

Private Function GetCurrentMailItem() As Outlook.MailItem
    Dim myOlApp As Outlook.Application
    Set myOlApp = CreateObject("Outlook.Application")
    Select Case TypeName(myOlApp.ActiveWindow)
    ' Selection From Inbox Explorer
       Case "Explorer"
            Set GetCurrentMailItem = myOlApp.ActiveExplorer.Selection.Item(1)
    ' Selection by opening Email Window
       Case "Inspector"
            Set GetCurrentMailItem = myOlApp.ActiveInspector.CurrentItem
        Case Else
    End Select
    'If Not TypeName(GetCurrentItem) = "MailItem" Then
    '   Set GetCurrentItem = Nothing
    'End If
    Set myOlApp = Nothing
End Function

Public Sub ReplyWithAttach()

    'Make declarations
   
    'Dim myInspector As Outlook.Inspector
   Dim myItem As Outlook.MailItem
    Dim myReplyItem As Outlook.MailItem
    Dim myAttachments As Outlook.Attachments
    Dim myReplyAttachments As Outlook.Attachments
    Dim fso
    Dim TempFolder As String
   
    Set fso = CreateObject("Scripting.FileSystemObject")
    TempFolder = fso.GetSpecialFolder(TemporaryFolder)
   
    'Set myInspector = myOlApp.ActiveInspector
   
    'Create variable to store files names 10 max if you need more then 10, change the value below
   Dim filenames(10) As String
   
    'If Not TypeName(myInspector) = "Nothing" Then
       'If TypeName(myInspector.CurrentItem) = "MailItem" Then
            'Set myItem = myInspector.CurrentItem
        Set myItem = GetCurrentMailItem()
        If Not myItem Is Nothing Then
            Set myAttachments = myItem.Attachments
            If myAttachments.Count > 0 Then
                For Count = 1 To myAttachments.Count
                    myAttachments.Item(Count).SaveAsFile TempFolder & "\" & myAttachments.Item(Count).DisplayName
                    filenames(Count) = myAttachments.Item(Count).DisplayName
                Next
               
                'Set myItem = myInspector.CurrentItem
               Set myReplyItem = myItem.Reply
                Set myReplyAttachments = myReplyItem.Attachments
               
                For Count = 1 To myAttachments.Count
                    myReplyAttachments.Add TempFolder & "\" & filenames(Count), olByValue, 1
                    myReplyItem.Display
                    fso.DeleteFile TempFolder & "\" & filenames(Count)
                Next
               
            End If
        Else
            MsgBox "The item is of the wrong type."
        End If
        Set myItem = Nothing
    'End If
End Sub

4. Right-click on the toolbar > Customize > Commands > Rearrange Commands
5. Select Toolbar > Standard > Add
6. and choose Macro

Comments

Popular posts from this blog

Save Settings for TeamViewer Portable

cos(π/9)*cos(2π/9)*cos(3π/9)*cos(4π/9)

Windows 7 / Windows Search 4 does NOT support UNC network location indexing