Partager via


AgingProperties

OK- everyone reading my blog knows that I love NewsGator. (Hey- NG dudes: why aren’t you advertising on Office Online Marketplace? Someone posted a comment to one of my earlier blogs asking this great question).

Well, I now am monitoring a lot of newsfeeds, but it’s time to clean house. IOW, I can’t keep all of these old messages around. Outlook has the super-cool AutoArchive feature that expunges old messages, moving them into a folder or deleting them altogether. Additionally, Outlook lets me have a global setting but I can also have specific settings for each folder. I prefer this because there are some RSS feeds whose messages I want around longer than others. Peter Torr’s blog (https://blogs.msdn.com/ptorr/) is one I like to have around for reference material. (It’s no secret he is brilliant).

 

There’s the problem: every time I add a new folder, I have to set each folders custom AutoArchive settings in the UI. Not fun when I have a lot of folders.

So, I have written some code to do it for me, and today I will connect to a button.

 

Here’s the deal (big thanks to Sue Mosher, Slipstick.com, and CDO Live with this link for getting me going (https://www.cdolive.com/cdo10.htm)

Let me break it down. First, I get a reference to the Mapi.Folder object for the target folder. The folder has a collection of hidden messages (HiddenMessages). In this messages is one that is of a specific type: IPC.MS.Outlook.AgingProperties (yeah, another barely known class type in the Mapi world!). You can filter the messages collection for that type or just loop through to find it. Filtering is usually more efficient, but I was looping when I wrote this code (blah). The Message in questions has some fields that are specific to the AutoArchive settings. I grab these using some constants defined earlier (just follow the CDOLive link to see what they are and what they mean). Then, I can read/write the props. Make sure you call the Update method of the Message when you are done setting the props.

Here’s the snippet:

'I acquire a reference to the MAPIFolder earlier, get

'its folder id and store id. These match the Mapi.Folder ones,

'so I can pass them in here and get the Mapi.Folder

  Set fld = objSession.GetFolder(sFolderID, sStoreID)

    Dim objMessages As Messages

    Dim objFilter As Object

    'I have a little userform I pop up to display the props

    Dim f As frmProps

    Dim objMessage As MAPI.Message

    Set objMessages = fld.HiddenMessages

    If Not objMessages Is Nothing Then

      For Each objMessage In objMessages

        If objMessage.Type = "IPC.MS.Outlook.AgingProperties" Then

          Set f = New frmProps

          Set objFields = objMessage.Fields

          If Not objFields Is Nothing Then

            Set objField = objFields.Item(CdoPR_AGING_PERIOD)

            'Here is an example of changing the value and updating

            objField.Value = 2

            objMessage.Update

            Set objField = Nothing

            f.txtPeriod.Text = objField.Value

            Set objField = objFields.Item(CdoPR_AGING_GRANULARITY)

            f.cboGranularity.AddItem objField.Value

            Set objField = Nothing

            Set objField = objFields.Item(CdoPR_AGING_FILENAME)

            f.txtPath.Text = objField.Value

            Set objField = Nothing

            Set objField = objFields.Item(CdoPR_PR_AGING_AGE_FOLDER)

            f.chkEnabled.Value = objField.Value

            Set objField = Nothing

            Set objField = objFields.Item(CdoPR_AGING_DELETE_ITEMS)

            If objField.Value Then

              f.optDelete.Value = True

            Else

              f.optMove.Value = True

            End If

          End If

          f.Show vbModal

          Exit For

        End If

      Next objMessage

    End If

 

Now, I will make adjustments so that custom AutoArchive settings just get placed on whatever my selected folder is in my Outlook.Explorer. I will also check for multiple folders selected in the explorer. I will then hook it up to a button. In this way, I can add newsfeeds all day, select the folders I want and with one click, apply autoarchive settings of my choosing.

 

Make sure you check out the MSDN Office Developer Center (https://msdn.microsoft.com/office)

Rock on!

Comments

  • Anonymous
    February 03, 2004
    NewsGator is indeed listed in the Office Marketplace...look under "messaging tools". Or did you mean something else?
  • Anonymous
    February 03, 2004
    The comment has been removed
  • Anonymous
    March 31, 2004
    This sounds like exactly what I have been frustrated with. The simple fact that microsoft has not implimented some sort of tree structure/selecting function to change the 'autoarchiving' on/off function for multiple folders at once is ridiculous.

    Plus, setting autoarchive to on for a folder 'should' by all logical means apply to all messages and subfolders within it..... But of course microsoft didn't do that. Not very logical imo.

    Any chance that what you are doing is something that will be shared and able to apply to outlook to increase its functionality?

    Thanks,
    J
    s a n d s r f r @ y a h o o (dot com)
  • Anonymous
    April 04, 2004
    I just copy & pasted your code snippet into a module in Outlook, and I got some error messages, stating that the the types "Message" and "frmProps" weren't defined. Do I need to add a reference to a non-default type library, or is there more code than what you posted?

    If it matters, I'm using Outlook 2003.

    Thanks!
  • Anonymous
    May 21, 2004
    This snippet has been a life saver. I'd got most of the way there but realised that the objMessage.update was the crucial missing link.

    For info, I am doing a recursive change down
    a particular top-level folder to set a
    specific archive folder for all the sub-folders.

    Many thanks.
  • Anonymous
    June 02, 2004
    John Griffiths, could I get a copy of your code with the sub folder addition? If you could email it to me at rbmadison@hotmail.com It's exactly what I've been looking for and would save me so much time trying to figure it out myself.

    Thanks a ton in advance!
  • Anonymous
    June 12, 2004
    The comment has been removed
  • Anonymous
    June 15, 2009
    PingBack from http://einternetmarketingtools.info/story.php?id=18601