Results 1 to 7 of 7
  1. #1
    RayMilhon is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,065

    MS Outlook

    Is it possible to setup a MS Outlook Macro to automatically save an attachment from a specific sender?

  2. #2
    June7's Avatar
    June7 is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    May 2011
    Location
    The Great Land
    Posts
    52,815
    I don't know about 'automatic' - some event must occur.

    Do you need code for grabbing the attachment? http://stackoverflow.com/questions/5...ing-access-vba

    Will probably need to modify to look for the specific sender email address in the From element.
    How to attach file: http://www.accessforums.net/showthread.php?t=70301 To provide db: copy, remove confidential data, run compact & repair, zip w/Windows Compression.

  3. #3
    RayMilhon is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,065
    The event is the arrival of the email. It occurs around 3 AM on a daily basis. What I want is when the email arrives the excel file is saved to a specific folder on the network. Then I will have an Access Database that uses the Windows Scheduler to start it at around 6 AM. In the Autoexec macro there will be code that will import that excel spreadsheet into MS Access and then run a query that will append the records in the Excel file into the table I created for this data. The Macro will only fire the subroutine that does the append if the Database is opened between 6 AM and 7 AM otherwise the db will open to the main form for use during the workday.

  4. #4
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    If I had to bet, there's a way within Outlook, but I've always done it from Access since I'm more comfortable with that model. One option would be to create an Access db that does it, and fire that off from an Outlook rule. You might try a more Outlook focused forum and see if there's a way within Outlook, which would be cleaner.
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  5. #5
    RayMilhon is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,065
    thanks Paul, That's my next step

  6. #6
    pbaldy's Avatar
    pbaldy is offline Who is John Galt?
    Windows XP Access 2007
    Join Date
    Feb 2010
    Location
    Nevada, USA
    Posts
    22,518
    No problem, post back if you find something good. I do a number of automated imports from email attachments (and email bodies). I do it all from Access, looping the inbox. I've always felt there must be a better way from Outlook directly, but never had time to research it (it's always "we need this running right away!").
    Paul (wino moderator)
    MS Access MVP 2007-2019
    www.BaldyWeb.com

  7. #7
    RayMilhon is offline VIP
    Windows 7 64bit Access 2010 32bit
    Join Date
    Aug 2011
    Location
    Southern California
    Posts
    1,065

    MS Outlook

    This is what I found. Still testing but looks good so far. Will let everyone know on Monday if it's successful or not.

    The NewMailEx Subroutine fires everytime a new email is received. (Actually I believe it's more often than that but the others are irrelevant to what I'm doing. So the line in the code below "if olitem.class = olmail " Checks to make sure it's an email and does nothing for everything else.

    Code:
    Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
    
        Dim arr() As String
        Dim lngCnt As Long
        Dim olAtt As Attachment
        Dim strFolder As String
        Dim strFileName As String
        Dim strNewFolder
        Dim olns As Outlook.NameSpace
        Dim olItem As MailItem
        
        'Set working folder
        'strFolder = "D:\Test"
        strFolder = "\\192.168.114.17\HVVHOMEFOLDERS\RMILHON\DEVELOPMENT\SENIOR_PROGRAMMING"
        On Error Resume Next
        Set olns = Application.Session
        arr = Split(EntryIDCollection, ",")
        On Error GoTo 0
        
        For lngCnt = 0 To UBound(arr)
            Set olItem = olns.GetItemFromID(arr(lngCnt))
            'Check new item is a mail message
            If olItem.Class = olMail Then
                'Force code to count attachments
                DoEvents
                'Debug.Print olItem.SenderEmailAddress
                If olItem.SenderEmailAddress Like "*HDMG-IDM*" Then
                    For Each olAtt In olItem.Attachments
                        'Check attachments have at least 5 characters before matching a ".xlsx" string
                        If Len(olAtt.FileName) >= 5 Then
                            If Right$(olAtt.FileName, 5) = ".xls" Then
                                strFileName = strFolder & "\" & olAtt.FileName
                                'Save xl attachemnt to working folder
                                olAtt.SaveAsFile strFileName
                            End If
                        End If
                    Next
                End If
            End If
        Next
        Set olns = Nothing
        Set olItem = Nothing
    End Sub

Please reply to this thread with any new information or opinions.

Similar Threads

  1. Replies: 0
    Last Post: 12-15-2014, 08:18 AM
  2. Outlook
    By donillo in forum Programming
    Replies: 12
    Last Post: 07-23-2014, 09:53 AM
  3. Replies: 11
    Last Post: 05-20-2014, 11:32 AM
  4. Assigning Outlook task from shared Outlook mailbox
    By Remster in forum Programming
    Replies: 2
    Last Post: 11-16-2011, 04:38 AM
  5. Outlook
    By andysmith652 in forum Access
    Replies: 5
    Last Post: 10-01-2010, 06:31 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Other Forums: Microsoft Office Forums