My Assistant
![]()
Custom Search
|
![]() ![]() |
![]() |
![]() Post#1 | |
Posts: 65 Joined: 29-January 17 ![]() | I have Office 365. I would like to be able, upon the receipt of an email with a specifically named attachment, to have that file automatically saved. I have found the following code which i have been unable to make work. CODE Option Explicit Public WithEvents olItems As Outlook.Items Private Sub Application_Startup() Set olItems = Session.GetDefaultFolder(olFolderInbox).Items olItems_ItemAdd End Sub Private Sub olItems_ItemAdd(ByVal Item As Object) Dim NewMail As Outlook.MailItem Dim Atts As Attachments Dim Att As Attachment Dim strPath As String Dim strName As String If Item.Class = olMail Then Set NewMail = Item End If Set Atts = Item.Attachments If Atts.Count > 0 Then For Each Att In Atts 'Replace "test" with what you want to look for in attachment name If InStr(LCase(Att.FileName), "TAFC_Bulk_Emailing_Data") > 0 Then 'Use your wanted destination folder path to save the attachments strPath = "C:\users\dave\desktop\" strName = NewMail.Subject & " " & Chr(45) & " " & Att.FileName Att.SaveAsFile strPath & strName End If Next End If End Sub I have used SELFCERT to self certify the code, which I believe I have to do, which i think that I have done correctly. I do not know whether this code is designed to work :- a. Automatically, as the email is received b. After the email is opened c. after firing up Outlook. Whatever, I am unable to get the code to save the file. Are you able to assist please? This post has been edited by MisterChips: Feb 11 2019, 11:06 AM |
![]() Post#2 | |
![]() Posts: 2,178 Joined: 4-February 07 From: USA, Florida, Delray Beach ![]() |
P.S. - Uses Early Binding. This post has been edited by ADezii: Feb 11 2019, 01:09 PM |
![]() Post#3 | |
![]() UtterAccess VIP Posts: 10,908 Joined: 6-December 03 From: Telegraph Hill ![]() | @ADezii, This looks like the code should reside in Access rather than Outlook. It might need some adjusting to run in Outlook (probably just remove a load of object variables) d -------------------- Regards, David Marten |
![]() Post#4 | |
![]() Posts: 2,178 Joined: 4-February 07 From: USA, Florida, Delray Beach ![]() | ![]() Thanks, totally missed that point! |
![]() Post#5 | |
![]() Posts: 2,178 Joined: 4-February 07 From: USA, Florida, Delray Beach ![]() | You can also consider using the Outlook Application's NewMail() Event which fires when new Messages arrive in the Inbox and before Client Rule processing occurs. |
![]()
Custom Search
|
![]() | Search Top Lo-Fi | 21st February 2019 - 11:52 PM |