using script rule to save attachments on arrival Outlook 2010

Status
Not open for further replies.
Outlook version
Outlook 2010 32 bit
Email Account
IMAP
Thanks for the wonderful educational post on saving attachments to the hard drive, Diane! I tried to post this question under that stream, but kept getting errors, so decided to try this method.
I am new to VBA with Outlook.
I am trying to make a rule that runs on message arrival to save all attachments to a folder.
I pasted in the code for “run a script rule to save attachments” as specified into the VBA editor and
I created the following rule called save attachments on arrival:
Apply this rule when the message arrives
which has an attachment
and on this computer only
run Project1.ThisOutlookSession.SaveAttachments
Unfortunately, the rule does NOT run on arrival of the message. It DOES work perfectly when the rule is run manually.

I am trying to solve a problem for a small client who has been using Eudora for years and Eudora automatically saves every attachment to an Attachment directory on arrival. This VBA rule script seems like it could be the simplest solution to make Outlook feel more like Eudora, if I can reliably make it run on arrival. Also I would need to be able to set up this rule with this script on multiple computers that currently do not have VB installed. Is this even possible?

I am still testing the Eudora environment to understand how it handles attachments of the same name and signatures, but I have not completed that assessment yet.

I am using VBA 2015 Community in a Windows 7 environment running Outlook 2010.

Thanks for your help!
 
Also I would need to be able to set up this rule with this script on multiple computers that currently do not have VB installed. Is this even possible?
You need VBA addin enabled in Outlook - nothing more - so yes, it will work.

Try adding a module to outlook (right click on Project1 in the editor > New > Module) and putting the macro in it - run a script rules usually work better if the script isn't in ThisOutlookSession (at least for me). Or, forget the script and use an itemadd macro. I have an itemadd macro at Save Attachments to the Hard Drive
 
Thanks, Diane! I liked the sound of the item add so I just copied the itemadd from your link [this macro runs (automatically) on messages as they are added to the Inbox. Put it in ThisOutlookSession.] into ThisOutlookSession and saved it. I created a folder for OLAttachements under My Documents (default location). I then sent a test email with attachments into the inbox, but it did not appear to run automatically when the email hit the inbox. Do I need to do something other than save it? This time it specifically advises saving in the ThisOutlookSession... should it be somewhere else?
 
You need this one in thisoutlooksession - macro security needs to be set to low and then you need to restart outlook to trigger the startup macro that sets the folder to watch. If macro security was already set to low, you can click in the application_startup macro and click Run to trigger it without restarting.
 
I restarted Outlook without any change, then I changed the outlook macro security as follows:
Outlook 2010 Options > Trust Center > Trust Center Settings > Macro Settings to be "enable all macros". I am still not seeing the attachments in the "My Documents>OLAttachments" folder.
Where do I find the application_startup macro to click Run?
(I am concerned about the implications about enable all macros for security)
 
This is the first part of the itemadd macro at the link i posted earlier (second macro on page) - the complete macro goes in ThisOutlookSession. Macro security should be set to low during testing - when it works, you can sign it using selfcert and change the security to allow signed macros.

When you restart outlook the startup macro should run, or click in the Application_Startup then click Run to kick start it during testing.

Code:
Private WithEvents olInboxItems As Items

Private Sub Application_Startup()
  Dim objNS As NameSpace
  Set objNS = Application.Session
  ' instantiate objects declared WithEvents
  Set olInboxItems = objNS.GetDefaultFolder(olFolderInbox).Items
  Set objNS = Nothing
End Sub


Private Sub olInboxItems_ItemAdd(ByVal Item As Object)
  On Error Resume Next
If Item.Attachments.Count > 0 Then

***snip***
 
Hi Diane,
I am just getting back to trying this again and I am still not seeing attachments saved into the OLAttachments folder that I created under My Documents.
I have my macro security set to execute all macros.
So for troubleshooting purposes, I intentionally introduced an error into the code just to see try to verify it was being executed.
This compile error happens immediately upon logging into Outlook, so this seems to prove that it is trying to execute.
(Invalid attribute in sub or Function) (my screen shot disappeared)

That seems to infer that the code is being executed, but for some reason is not saving the attachments.
Any suggestions on what else to check?
I am doing this with Outlook set up as IMAP for a FASTMAIL account this time.
I have not tried POP3 yet… does that make a difference on how this would work?
Thank you for your help!
 
IMAP can be a bit goofy as the full message isn't downloaded immediately, like it is with pop3. In Send & Receive settings (Ctrl+Alt+S, then Edit, select the imap account), are you downloading full messages?
 
Yes, I think I am set up to download the full message and I verified the inbox is a subscribed folder.
I was unable to attach a screen shot, but I have "download complete items including attachments for subscribed folders" selected under Receive mail items.

I noticed that this ItemAdd VBA code is set up for Application Startup.
I see there is an option in the dropdown on the right for NewMail instead of Startup. Would that make a difference?
When testing, I am always closing and re-starting Outlook, so Startup should be working, but it is still not saving the attachments to OLAttachments folder.

We are looking into setting up a POP3 account for testing, but have not had a chance to do that yet.
Your help is MUCH appreciated!
 
I noticed that this ItemAdd VBA code is set up for Application Startup.
The code in app startup (usually just sets a folder to watch, but could do more) is run when outlook starts. If it works once then dies, something is causing the macro to fail and forget the variable that was set. It could be a code failure (if you click End when the debugger comes up) or the variable is set to none in the code - in this case, setting olInboxItems = nothing in the macro that uses it would prevent it from working again.

I see there is an option in the dropdown on the right for NewMail instead of Startup. Would that make a difference?

I'm not sure where you are looking, but no, it probably won't make a difference.

Add msgbox "Macro running App Start" before the end sub in the app start macro and msgbox "Macro running - itemadd" at the beginning in the other macro and restart. Does either dialog box come up? If so, something else is failing.
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
F Avoid sending duplicate using Outlook script Outlook VBA and Custom Forms 2
A VBA Script to Forward Spam to AntiSpam Provider Using "Blank" Form Outlook VBA and Custom Forms 2
B Outlook Script ( using calendar function in a form) Outlook VBA and Custom Forms 3
H using VBA to edit subject line Outlook VBA and Custom Forms 0
e_a_g_l_e_p_i Need clarification on 2-Step Verification for Gmail using Outlook 2021 Using Outlook 10
e_a_g_l_e_p_i Outlook 2021 not letting me setup my Gmail using pop Using Outlook 1
Geldner Problem submitting SPAM using Outlook VBA Form Outlook VBA and Custom Forms 2
O How to find out the domain and server settings that my Outlook is using? Using Outlook 2
S Outlook 2019 Custom outlook Add-in using Visual Studio Outlook VBA and Custom Forms 0
D Outlook 2021 Using vba code to delete all my spamfolders not only the default one. Outlook VBA and Custom Forms 0
M using excel to sort outlook appointment items Outlook VBA and Custom Forms 4
R Advise on using multiple instances of network files based on customers Outlook VBA and Custom Forms 8
HarvMan Using Emojis in Outlook 365 Using Outlook 3
T Outlook 2019 Not Using Auto Compete After Deletion of 365 Using Outlook 1
M USING INITIALS AS RECIPIENTS Using Outlook 1
T Outlook 2019 Using Gmail aliases in Outlook Using Outlook 6
M Saving emails using Visual Basic - Selecting folder with msoFileDialogFolderPicker Outlook VBA and Custom Forms 6
Z Import Tasks from Access Using VBA including User Defined Fields Outlook VBA and Custom Forms 0
justicefriends How to set a flag to follow up using VBA - for addressee in TO field Outlook VBA and Custom Forms 11
M Extract "Date sent" from emails (saved to folder using drag and drop) Outlook VBA and Custom Forms 1
I Outlook for Mac 2019 using on desktop and laptop IMAP on both need help with folders Using Outlook 1
David McKay VBA to manually forward using odd options Outlook VBA and Custom Forms 1
H Stationery using between OL 2019 and OL 2010 Using Outlook 0
P Prevent Outlook 2016 from using DASL filter Using Outlook 4
O Calendar - Location: what happens when using my own way of entering locations Using Outlook 1
M Disable Contact Card Results when using "Search People" in Outlook Ribbon Using Outlook 7
K can't get custom form to update multiple contacts using VBA Outlook VBA and Custom Forms 3
S Outlook VBA How to adapt this code for using in a different Mail Inbox Outlook VBA and Custom Forms 0
pcunite Outlook 2019/O365 Build 13127.20408 errors when using MAPI calls Using Outlook 1
B Change Font and Font size using VBA Outlook VBA and Custom Forms 9
M Outlook 2013 reminder email by using Outlook vba Outlook VBA and Custom Forms 2
X Using Outlook 2013 and Outlook 365 Using Outlook 1
A Going to folder using shortcuts Using Outlook 3
A Outlook replies not using "delivered to" address in From Using Outlook 1
Terry Sullivan E-Mails Sent Using a Group Box Result in 70 Kickbacks Using Outlook 4
O Email not leaving Outbox when using Excel VBA to sync Outlook account Outlook VBA and Custom Forms 4
K Using Outlook 2016 to draw Using Outlook 1
O Outlook 365 - suddenly unable to send using Gmail POP3 Using Outlook 10
N Disable Auto Read Receipts sent after using Advanced Find Using Outlook 4
G Outlook 2016 sync contacts directly between phone and computer using outlook 2016 Using Outlook 0
L Moving emails with similar subject and find the timings between the emails using outlook VBA macro Outlook VBA and Custom Forms 1
O Save attachments using hotkey without changing attributes Outlook VBA and Custom Forms 1
J Add an Attachment Using an Array and Match first 17 Letters to Matching Template .oft to Send eMail Outlook VBA and Custom Forms 2
A Edit subject - and change conversationTopic - using VBA and redemption Outlook VBA and Custom Forms 2
A Using or not using apostrophes in search terms has this changed? Using Outlook 0
O Office 365 using POP3 on both laptop and desktop Using Outlook 0
M Using field names to capture a data element Using Outlook 0
B Vba to monitor time to respond to emails using a shared mailbox Outlook VBA and Custom Forms 5
B Looking to get the Recipient email address (or even the "friendly name") from an email I am replying to using VBA Outlook VBA and Custom Forms 4
D Using a VBA Custom Form to Send Reoccurring Email Upon Task Completion Outlook VBA and Custom Forms 4

Similar threads

Back
Top