Good afternoon all.
I have this genral code which is run from OL XP and it saves attachments to a folder.
What I need to know is how do I refer to subfolders of the Inbox?
Specifically this line
( I have done a bit of research on the net & I have an outlook 2002 ref but I have not had any joy.)
I have this genral code which is run from OL XP and it saves attachments to a folder.
What I need to know is how do I refer to subfolders of the Inbox?
Specifically this line
Rich (BB code):
Set fld2SaveAtt = ns.GetDefaultFolder(olFolderInbox)
( I have done a bit of research on the net & I have an outlook 2002 ref but I have not had any joy.)
Rich (BB code):
Sub SaveAtts()
Dim ns As NameSpace
Dim fld2SaveAtt As MAPIFolder
Dim MailItem As Object
Dim Att As Attachment
Dim FileName As String
Dim intFiles As Integer
On Error GoTo HandleError
Set ns = GetNamespace("MAPI")
Set fld2SaveAtt = ns.GetDefaultFolder(olFolderInbox)
intFiles = 0
If fld2SaveAtt.Items.Count = 0 Then
MsgBox "There were no messages found in your Inbox."
Exit Sub 'there are no messages, so Exit the Sub
End If
'Loop through Mail Items
For Each MailItem In fld2SaveAtt.Items
'Loop through any attachments
For Each Att In MailItem.Attachments
FileName = "C:Attachments" & Trim(Att.FileName)
Att.SaveAsFile FileName
intFiles = intFiles + 1
Next
Next
' Show summary message
If intFiles > 0 Then
MsgBox intFiles & " attachments were saved to " ^ _
"C:Attachments."
Else
MsgBox "No attachments were found"
End If
Set Att = Nothing
Set MailItem = Nothing
Set ns = Nothing
Exit Sub
HandleError:
MsgBox "Error: " & Err.Number & vbCrLf & _
"Description: " & Err.Description & vbCrLf & _
"The file's name is " & FileName
intFiles = intFiles - 1
Resume Next 'Continue saving attachments
End Sub