Consulting

Results 1 to 2 of 2

Thread: LazyDBA.com save attachments automatically in Outlook

  1. #1

    Post LazyDBA.com save attachments automatically in Outlook

    In my Outlook I have a folder “LazyDBA.MsSQLDBA” and I have a subfolder “Details”

    When I receive a mail from *email address removed* I would like than VBA extract all attachments in the message and save it in LazyDBA.MsSQLDBA\Details. (The attachments are .msg)

    All should be done automatically.

    VBA experts, I need your help…. A complete solution will be appreciate

    Thanks

    Newbie in VBA


    Don't post email address you don't want spammed into obvlivion ~Oorang

  2. #2
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    Put this in your OutlookSession Module:
    [VBA]Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
    Dim mai As Object
    Dim strEntryIDs() As String
    Dim lngEntryIDIndx As Long
    Dim ns As Outlook.NameSpace
    Dim mlItm As Outlook.MailItem
    Dim atchmnt As Outlook.Attachment
    Set ns = Outlook.Session
    'You can get several mail items at a time:
    strEntryIDs = Split(EntryIDCollection, ",")
    'Loop through mail items:
    For lngEntryIDIndx = 0 To UBound(strEntryIDs)
    Set mai = ns.GetItemFromID(strEntryIDs(lngEntryIDIndx))
    'Not all entry ids will be for Mail Items:
    If TypeOf mai Is Outlook.MailItem Then
    'You don't have to convert to a Mail Item object, I just prefer to
    'so I can use the intellisense.
    Set mlItm = mai
    If LCase$(mlItm.SenderEmailAddress) = "test@example.com" Then
    For Each atchmnt In mlItm.Attachments
    'This will overwrite without prompting, watch it:
    atchmnt.SaveAsFile "C:\Test\" & atchmnt.FileName
    Next
    End If
    End If
    Next
    End Sub[/VBA]
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

Posting Permissions

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