Results 1 to 2 of 2

Thread: Macro to save attachment to folder not running

  1. #1

    Macro to save attachment to folder not running

    I have a macro set to run when a rule identifies a new email with a keyword in the subject. For some reason, it is no longer running, even when I run it manually. When I have tried "Public Sub SaveEmailAttachmentsToFolder(item As Outlook.MailItem)" nothing happens when I run the macro.

    When I declare "item as Outlook.MailItem" as Public after Option Explicit, the code will run but it errors out. The macro also no longer shows under "Run Script" in the rule.

    I have tried placing the code in Outlook Session and in a Module. I know I'm missing something but cannot figure out what it is.
    Option Explicit
    Public Sub SaveEmailAttachmentsToFolder(item As Outlook.MailItem)
    Dim I As Integer
    Dim Inbox As MAPIFolder
    Dim Atmt As Outlook.Attachment
    Dim strFileName As String
    Dim strDestFolder As String
    On Error GoTo ThisMacro_err
    strDestFolder = "c:\Symphony Development\import\"
    For Each Atmt In item.Attachments
        strFileName = Atmt.DisplayName
        If LCase(Right(strFileName, 3)) = "csv" Or LCase(Right(strFileName, 4)) = "xlsm" Or LCase(Right(strFileName, 4)) = "xlsx" Then
            Atmt.SaveAsFile strDestFolder & strFileName
        End If
    Set Inbox = Nothing
    Exit Sub
    End Sub

  2. #2
    VBAX Mentor skatonni's Avatar
    Jun 2006
    You have to pass a mailitem.

    Sub Maiitem_Parameter_For_SaveEmailAttachmentsToFolder()
        ' first open an appropriate mailitem
        SaveEmailAttachmentsToFolder ActiveInspector.currentItem
    End Sub
    Assuming your code runs now. It is possible running code from rules has been disabled. Google it for ways to re-enable. If not allowed you can switch to ItemAdd or NewMaiEx.
    To debug, mouse-click anywhere in the code. Press F8 repeatedly to step through the code.

    If your problem has been solved in your thread, mark the thread "Solved" by going to the "Thread Tools" dropdown at the top of the thread. You might also consider rating the thread by going to the "Rate Thread" dropdown.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts