Saving attachment from shared mailbox




I have the following code below that allows me to save all the attachments
from my own Inbox.

Sub GetAttachments()

On Error GoTo GetAttachments_err

Dim ns As NameSpace
Dim Inbox As MAPIFolder
Dim SubFolder As MAPIFolder
Dim Item As Object
Dim Atmt As Attachment
Dim FileName As String
Dim i As Integer

Set ns = GetNamespace("MAPI")
Set Inbox = ns.GetDefaultFolder(olFolderInbox)
i = 0

If Inbox.Items.Count = 0 Then
MsgBox "There are no messages in the Inbox!", vbInformation, "Nothing
Exit Sub
End If

For Each Item In Inbox.Items
For Each Atmt In Item.Attachments
FileName = "C:\Documents and
Settings\earpn\Desktop\Developments\Attachments\" & Atmt.FileName
Atmt.SaveAsFile FileName
i = i + 1
Next Atmt
Next Item

If i > 0 Then
MsgBox "I found " & i & " attached files." _
& vbCrLf & "I have saved them to C:\Documents and
Settings\earpn\Desktop\Developments\Attachments." _
& vbCrLf, vbInformation, "Finished!"
MsgBox "I didn't find any attached files in your mail.", vbInformation,
End If


Set Atmt = Nothing
Set Item = Nothing
Set ns = Nothing

Exit Sub


MsgBox "An unexpected error has occurred." _
& vbCrLf & "Please note and report the following information." _
& vbCrLf & "Macro Name: GetAttachments" _
& vbCrLf & "Error Number: " & Err.Number _
& vbCrLf & "Error Description: " & Err.Description _
, vbCritical, "Error!"

Resume GetAttachments_exit

End Sub

I now need to enable this to save the attachments from a shared mailbox that
i have access too and to save them into specific folders based on the first 6
characters of the attachments file name.

Is this possible? If so does anyone have any ideas of how to do it.

Folder will be a 6 digit number
E-mail will be say (e-mail address removed) & it'll be that e-mails Inbox i want to access

Thanks in advance

Michael Bauer [MVP - Outlook]

For accessing a shared mailbox see the GetSharedDefaultFolder function. For
text parsing the functions Instr, Left, Right, and Mid are useful.

Best regards
Michael Bauer - MVP Outlook

: Outlook Categories? Category Manager Is Your Tool
: VBOffice Reporter for Data Analysis & Reporting
: <>

Am Mon, 20 Jul 2009 07:25:01 -0700 schrieb N1KO:

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