Is it possible to setup a MS Outlook Macro to automatically save an attachment from a specific sender?
Is it possible to setup a MS Outlook Macro to automatically save an attachment from a specific sender?
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.
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.
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.
thanks Paul, That's my next step
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!").
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