Help!

MailItem from an RSS feed

 
  

Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> Programming VBA RSS
Next:  How do I take back an email to prevent recipient ..  
Author Message
Dan
External


Since: Jun 25, 2004
Posts: 557



PostPosted: Thu Jul 02, 2009 5:38 pm    Post subject: MailItem from an RSS feed
Archived from groups: microsoft>public>outlook>program_vba (more info?)

I am using Outlook 2007 and VB6. I am using Outlook Automation in a VB
program to choose certain Outlook messages from a folder called Archive, save
them as MSG files, and then delete the messages. It works fine when only
email messages are in the folder.

But occasionally I subscribe to RSS feeds, and sometimes I drag the messages
from the RSS feeds to the Archive folder. I have to skip over those because I
can't treat them as MailItem objects.

Here is a simplified view of the code I'm using:

Dim DateTimeStr As String
Dim FilterStr As String
Dim Message As Outlook.MailItem
Dim MessageFolder As Object
Dim MessageList As Object
Dim ObjItem As Object
Dim OutlookApp As Object
Dim OutlookNamespace As Object
Dim SelectedOutlookFolder as Outlook.Folder

Set OutlookApp = GetObject(, "Outlook.Application")
Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")
Set MessageFolder =
OutlookNamespace.GetFolderFromID(SelectedOutlookFolder.EntryID,
SelectedOutlookFolder.StoreID)

DateTimeStr = Format("7/1/2009 12:00am", "ddddd h:nn AMPM")
FilterStr = "[SentOn] < '" & DateTimeStr & "'"
Set MessageList = MessageFolder.Items.Restrict(FilterStr)

If Not MessageList Is Nothing Then
For Each ObjItem In MessageList
Set Message = Nothing
On Error Resume Next
Set Message = ObjItem
If Not Message Is Nothing Then
End If
Next ObjItem
End If

Is there any way that I can test for the RSS feed messages in this same loop
and save them as MSG files also? Thanks for your help.
Back to top
Sue Mosher [MVP]
External


Since: Mar 19, 2009
Posts: 41



PostPosted: Thu Jul 02, 2009 9:46 pm    Post subject: Re: MailItem from an RSS feed [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

This is the problem statement:

Dim Message As Outlook.MailItem

It makes an assumption that all items being processed are MailItem objects.
If you use Object instead of MailItem for the declaration, your code should
still work fine.

Also, you should not delete messages inside a For Each ... Next loop.
Instead, use a down-counting loop, e.g.:

Dim ObjItem As Object
count = MessageList.Count
For i = count to 1 Step -1
Set ObjItem = MessageList(i)
ObjItem.SaveAs "<some path>", olMSG
ObjItem.Delete
Next

--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook 2007 Programming:
Jumpstart for Power Users and Administrators
http://www.outlookcode.com/article.aspx?id=54


"Dan" <Dan.RemoveThis@discussions.microsoft.com> wrote in message
news:39076CBB-6480-4A98-8DDA-7AEF32DC9957@microsoft.com...
>I am using Outlook 2007 and VB6. I am using Outlook Automation in a VB
> program to choose certain Outlook messages from a folder called Archive,
> save
> them as MSG files, and then delete the messages. It works fine when only
> email messages are in the folder.
>
> But occasionally I subscribe to RSS feeds, and sometimes I drag the
> messages
> from the RSS feeds to the Archive folder. I have to skip over those
> because I
> can't treat them as MailItem objects.
>
> Here is a simplified view of the code I'm using:
>
> Dim DateTimeStr As String
> Dim FilterStr As String
> Dim Message As Outlook.MailItem
> Dim MessageFolder As Object
> Dim MessageList As Object
> Dim ObjItem As Object
> Dim OutlookApp As Object
> Dim OutlookNamespace As Object
> Dim SelectedOutlookFolder as Outlook.Folder
>
> Set OutlookApp = GetObject(, "Outlook.Application")
> Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")
> Set MessageFolder =
> OutlookNamespace.GetFolderFromID(SelectedOutlookFolder.EntryID,
> SelectedOutlookFolder.StoreID)
>
> DateTimeStr = Format("7/1/2009 12:00am", "ddddd h:nn AMPM")
> FilterStr = "[SentOn] < '" & DateTimeStr & "'"
> Set MessageList = MessageFolder.Items.Restrict(FilterStr)
>
> If Not MessageList Is Nothing Then
> For Each ObjItem In MessageList
> Set Message = Nothing
> On Error Resume Next
> Set Message = ObjItem
> If Not Message Is Nothing Then
> End If
> Next ObjItem
> End If
>
> Is there any way that I can test for the RSS feed messages in this same
> loop
> and save them as MSG files also? Thanks for your help.
Back to top
Dan
External


Since: Jun 25, 2004
Posts: 557



PostPosted: Thu Jul 02, 2009 9:46 pm    Post subject: Re: MailItem from an RSS feed [Login to view extended thread Info.]
Archived from groups: per prev. post (more info?)

Sue,

Thank you. You solved my problem.

Dan

"Sue Mosher [MVP]" wrote:

> This is the problem statement:
>
> Dim Message As Outlook.MailItem
>
> It makes an assumption that all items being processed are MailItem objects.
> If you use Object instead of MailItem for the declaration, your code should
> still work fine.
>
> Also, you should not delete messages inside a For Each ... Next loop.
> Instead, use a down-counting loop, e.g.:
>
> Dim ObjItem As Object
> count = MessageList.Count
> For i = count to 1 Step -1
> Set ObjItem = MessageList(i)
> ObjItem.SaveAs "<some path>", olMSG
> ObjItem.Delete
> Next
>
> --
> Sue Mosher, Outlook MVP
> Author of Microsoft Outlook 2007 Programming:
> Jumpstart for Power Users and Administrators
> http://www.outlookcode.com/article.aspx?id=54
>
>
> "Dan" <Dan.TakeThisOut@discussions.microsoft.com> wrote in message
> news:39076CBB-6480-4A98-8DDA-7AEF32DC9957@microsoft.com...
> >I am using Outlook 2007 and VB6. I am using Outlook Automation in a VB
> > program to choose certain Outlook messages from a folder called Archive,
> > save
> > them as MSG files, and then delete the messages. It works fine when only
> > email messages are in the folder.
> >
> > But occasionally I subscribe to RSS feeds, and sometimes I drag the
> > messages
> > from the RSS feeds to the Archive folder. I have to skip over those
> > because I
> > can't treat them as MailItem objects.
> >
> > Here is a simplified view of the code I'm using:
> >
> > Dim DateTimeStr As String
> > Dim FilterStr As String
> > Dim Message As Outlook.MailItem
> > Dim MessageFolder As Object
> > Dim MessageList As Object
> > Dim ObjItem As Object
> > Dim OutlookApp As Object
> > Dim OutlookNamespace As Object
> > Dim SelectedOutlookFolder as Outlook.Folder
> >
> > Set OutlookApp = GetObject(, "Outlook.Application")
> > Set OutlookNamespace = OutlookApp.GetNamespace("MAPI")
> > Set MessageFolder =
> > OutlookNamespace.GetFolderFromID(SelectedOutlookFolder.EntryID,
> > SelectedOutlookFolder.StoreID)
> >
> > DateTimeStr = Format("7/1/2009 12:00am", "ddddd h:nn AMPM")
> > FilterStr = "[SentOn] < '" & DateTimeStr & "'"
> > Set MessageList = MessageFolder.Items.Restrict(FilterStr)
> >
> > If Not MessageList Is Nothing Then
> > For Each ObjItem In MessageList
> > Set Message = Nothing
> > On Error Resume Next
> > Set Message = ObjItem
> > If Not Message Is Nothing Then
> > End If
> > Next ObjItem
> > End If
> >
> > Is there any way that I can test for the RSS feed messages in this same
> > loop
> > and save them as MSG files also? Thanks for your help.
>
>
>
>
Back to top
Display posts from previous:   
Post new topic   General Reply to Topic (not reply to a specific post)    Forums Home -> Programming VBA All times are: Eastern Time (US & Canada) (change)
Page 1 of 1

 
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum