C
Curtis C
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.
*** Sent via Developersdex http://www.developersdex.com ***
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.
*** Sent via Developersdex http://www.developersdex.com ***