[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now


How can I save an attachment from an RSS Feed folder

Posted on 2012-12-29
Medium Priority
Last Modified: 2012-12-30
I have subscribed to an RSS Feed of MP3 files that I save in a sub folder of my RSS Feeds folder called "Italian Mags MP3".  Each email contains an MP3 file and the first line in each email contans a code that identifies the file in the format  "a MP3 yyyy-mmn" where
    a is a two or 3 character code,
    MP3 is a constant  
   yyyy-mm is the year and month of the file and
   n is a further identifier of the file

What I would like is do develop an Outlook Rule or a VBA macro that runs as soon as the RSS Feed is updated that will save the attachment in a folder on my PC based on the month (mm) content of the first line of the email. Specifically the path would be C:\Users\Rob\Music\Italian\mm where mm is the month corresponding to the mm in the date component of the code.

If necessary I can easily write a VBA function that will extract the mm component I am looking for, but what I don't know is the best and easiest way to accomplish the rest, or if it is even possible.

I guess I need something that will
   Check RSS Feeds as soon as they hit this folder
   Run my function to determine the mm content
  Save the attachment in the appropriate folder

Can anyone suggest how I do this, of if I am asking too much of Outlook
Question by:Rob4077
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 2

Author Comment

ID: 38730238
Actually I just found an easier way to identify the month. The month can simply be identified as the month of the date when the file was sent
LVL 16

Accepted Solution

terencino earned 2000 total points
ID: 38731829
Hi Rob, I tested this in Outlook 2010, just place the code below into ThisOutlookSession, add a reference to Microsoft Scripting Runtime, save and restart Outlook. I modelled it as close as I can to the information you provided but there will likely be some errors before we get to the final product. I don't have the RSS feed, but essentially this code establishes a watch on the folder, and when an email is added to the folder, it triggers the macro. It uses a combination of MID & INSTR to find the relevant month, or you can substitute with Month(Item.ReceivedTime) if you prefer.
Option Explicit
' Adapted from Daniel Dusek http://stackoverflow.com/questions/12457471/how-do-i-set-a-macro-to-launch-every-time-an-email-arrives-in-a-certain-subfolde

Private Const ITALIAN_MP3_FOLDER As String = "Italian Mags MP3"
Private WithEvents m_outlookFolderItems As Outlook.Items

Private Sub Application_Startup()
End Sub

Private Sub m_outlookFolderItems_ItemAdd(ByVal Item As Object)
' You have new mail in folder ITALIAN_MP3_FOLDER
' Add reference to Microsoft Scripting Runtime
Dim att As Attachment, attFolder As String
' Identifies folder and creates new one if required
attFolder = "C:\Users\Rob\Music\Italian\" & Mid(Item.Subject, InStr(1, Item.Subject, "-") + 1, 2) & "\"
CheckFolder attFolder
If Item.Attachments.Count > 0 Then
  For Each att In Item.Attachments
    att.SaveAsFile attFolder & att.DisplayName
    'MsgBox "RSS MP3 saved to : " & attFolder & att.DisplayName
  Next att
End If

End Sub

Private Sub Initialize_Handler()
    Dim outlookFolder As Outlook.MAPIFolder
    Dim defaultRSSFolder As Outlook.MAPIFolder
    Dim outlookNameSpace As Outlook.NameSpace

    Set outlookNameSpace = Outlook.GetNamespace("MAPI")
    Set defaultRSSFolder = outlookNameSpace.GetDefaultFolder(olFolderRssFeeds)
    Set outlookFolder = defaultRSSFolder.Folders(ITALIAN_MP3_FOLDER)
    Set m_outlookFolderItems = outlookFolder.Items
End Sub

Private Sub CheckFolder(folder_name As String)
'Adapted from http://www.devguru.com/technologies/vbscript/quickref/filesystemobject_folderexists.html
Dim FSO As FileSystemObject, newfolder
Set FSO = New FileSystemObject
If Not FSO.FolderExists(folder_name) Then
   newfolder = FSO.CreateFolder(folder_name)
End If
End Sub

Open in new window

It has been adapted from a variety of sources on the web, referenced in the code if you want to check further there are some brilliant people out there who can make Outlook jump through hoops.

Let me know how you go

Author Comment

ID: 38731968
Hi Terry,
That is absolutely amazing!!!! I changed the code to take the date from the alternative you proveded, namely Month(Item.ReceivedTime), as it proved more reliable, but apart from that it worked first time. Thank you so much.

I am familiar with basic VBA code but what I don't understand is how the watch works. How did you know what code to use to watch for the arrival of an email into the feed (Sub m_outlookFolderItems_ItemAdd(ByVal Item As Object))? There must be somewhere that shows/lists the varous watches you can add to code.

Anyway I am very grateful that you put this together for me.
LVL 16

Expert Comment

ID: 38731996
Ha I'm amazed it worked first time, it is a credit to how well you have detailed your question.  I'm not all that familiar with VB so I learned quite a bit myself in the process, and it is only the tip of a very large iceberg I expect. When an item is moved to a folder it triggers a number of "events" (one being folder_ItemAdd) which is "handled" by Outlook. The WithEvents & Initialize_Handler code above allows the event to be detected by the programmer as well. There are lots of events, I just had a look in VBE at View > Object Browser. I'm going to hunt down some articles to help me transition a bit further along with VB, it is really powerful, and as you can see it works happily with VBA.


Author Comment

ID: 38732027
Thanks Terry, appreciate help very much, and the explanation of where to find more information. Like you I will have to hunt down some more information.

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Many people use more than one email account and so it becomes difficult for them to manage them when they use separate accounts,  so, in this article, I have shared an easy way to add Other Mail Accounts in your Google Inbox. It helps to combine all…
Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

649 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question