Looping Through The Inbox Collection

C

CC

I have some code to save attachments in my inbox, and it works OK,
except that the code loops inside the "Date Today" subgroup within the
inbox. If I do a "myFolder.Items.Count" I receive the correct number of
items within the entire inbox however, using the
"myFolder.Items.GetNext" loops within the "Date Today" group. My code
is:
___________________________________________________________
Dim objOL As Outlook.Application
Dim objMsg As Outlook.MailItem 'Object
Dim objAttachments As Outlook.Attachments
Dim objSelection As Outlook.Selection
Dim i As Long
Dim lngCount As Long
Dim strFile As String
Dim strFolderpath As String
Dim strDeletedFiles As String
Dim mail_count As Integer

strFolderpath = CreateObject("WScript.Shell").SpecialFolders(16)

On Error Resume Next
Set objOL = CreateObject("Outlook.Application")
Set myNms = objOL.GetNamespace("MAPI")
Set myFolder = myNms.GetDefaultFolder(olFolderInbox)
Set myExplorer = objOL.ActiveExplorer
Set myExplorer.CurrentFolder = myFolder

Set objMsg = myFolder.Items.GetFirst

mail_count = myFolder.Items.Count
Do While mail_count > 0
Set objSelection = objOL.ActiveExplorer.objMsg
strFolderpath = "C:\mail_attachments\"

For Each objMsg In objSelection

Set objAttachments = objMsg.Attachments
lngCount = objAttachments.Count

If lngCount > 0 Then
For i = lngCount To 1 Step -1
strFile = objAttachments.Item(i).FileName
strFile = strFolderpath & strFile
objAttachments.Item(i).SaveAsFile strFile
Next i

objMsg.Save

End If
Next
mail_count = mail_count - 1
Set objMsg = myFolder.Items.GetNext
Loop

ExitSub:

Set objAttachments = Nothing
Set objMsg = Nothing
Set objSelection = Nothing
Set objOL = Nothing
End Sub
___________________________________________________________
Any help would be greatly appreciated.
 
S

Sue Mosher [MVP-Outlook]

Since Outlook doesn't have any concept of "subgroup," I think you might need to explain what "Date Today" is.

Furthermore, you can't set the Selection collection.

--
Sue Mosher, Outlook MVP
Author of Configuring Microsoft Outlook 2003

and Microsoft Outlook Programming - Jumpstart for
Administrators, Power Users, and Developers
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top