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!
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
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
 
Outlook version
Outlook 2010 32 bit
Email Account
IMAP
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?
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
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.
 
Outlook version
Outlook 2010 32 bit
Email Account
IMAP
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)
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
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***
 
Outlook version
Outlook 2010 32 bit
Email Account
IMAP
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!
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
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?
 
Outlook version
Outlook 2010 32 bit
Email Account
IMAP
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!
 

Diane Poremsky

Senior Member
Outlook version
Outlook 2016 32 bit
Email Account
Office 365 Exchange
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
G Script Error message when trying to print e-mails using Outlook Mail Using Outlook 2
B Outlook Script ( using calendar function in a form) Outlook VBA and Custom Forms 3
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 5
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
Z Adding dropdown list using custom form Outlook VBA and Custom Forms 7
O Using .OST and .PST mail thru different providers Using Outlook 5
N Open & Save VBAProject.Otm using VBA Code Outlook VBA and Custom Forms 1
D Remove text in subject using VBA Outlook VBA and Custom Forms 4
P How to export voting results using VBA? Outlook VBA and Custom Forms 2
E Using the Like operator properly Outlook VBA and Custom Forms 1
R Using "check for duplicates" for existing contacts Using Outlook 2
S Find a cell value in excel using outlook vba Using Outlook 1
N Using email notification to update calendar events? Outlook VBA and Custom Forms 4
S Macro using .SendUsingAccount only works the first time, after starting Outlook Outlook VBA and Custom Forms 4
C Sync Calendars using WiFI Using Outlook 3
A Capturing Send Variables without using Application_ItemSend in ThisOutlookSession Outlook VBA and Custom Forms 8
L Using alpha numeric in email address Using Outlook 5
Sabastian Samuel HOW DO I FORWARD AN EMAIL WITH MACRO using an email that in the body of another email Outlook VBA and Custom Forms 3
D create an html table in outlook custom form 2010 using vba in MsAccess Outlook VBA and Custom Forms 7
D Print Attachments only in selected emails using a macro Outlook VBA and Custom Forms 3
B query outlook using vba Outlook VBA and Custom Forms 13
M Using conditional formatting on a shared calendar with categories Using Outlook 6
e_a_g_l_e_p_i A question about installing office 2013 Pro and using my .pst from office 2010 Using Outlook 12
A Forward Outlook Email by Filtering using Macro Rule Outlook VBA and Custom Forms 44
O How to paste website content using a specific font and removing URLs Using Outlook 2
P Replying to calendar item using VBA Outlook VBA and Custom Forms 4
N Export details to a excel spreadsheet using macros Using Outlook 0
R Toggle the Reading Pane using Keyboard Shortcut Using Outlook 0

Similar threads

Top