Saving attachment from shared mailbox

Status
Not open for further replies.
N

N1KO

Hi,

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

Found"

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!"

Else

MsgBox "I didn't find any attached files in your mail.", vbInformation,

"Finished!"

End If

GetAttachments_exit:

Set Atmt = Nothing

Set Item = Nothing

Set ns = Nothing

Exit Sub

GetAttachments_err:

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 aa@bb.com & it'll be that e-mails Inbox i want to access

Thanks in advance
 
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

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


> Hi,

> 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
> Found"
> 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!"
> Else
> MsgBox "I didn't find any attached files in your mail.",


vbInformation,
> "Finished!"
> End If

> GetAttachments_exit:

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

> Exit Sub

> GetAttachments_err:

> 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 aa@bb.com & it'll be that e-mails Inbox i want to


access

> Thanks in advance
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
L Attachment saving and tracking - PLEASE help! Outlook VBA and Custom Forms 5
V Saving attachment from outlook in My Documents Outlook VBA and Custom Forms 14
K Copy Subject Line When Saving Attachment Outlook VBA and Custom Forms 2
M Saving an attachment - outbox and sent mail conflicts Outlook VBA and Custom Forms 10
Rupert Dragwater Background colors not saving in Outlook 365 Using Outlook 15
R Saving Emails and Attachments as .msg file Using Outlook 3
CWM550 Saving Data: Don't check certain folders Using Outlook 2
M Saving emails using Visual Basic - Selecting folder with msoFileDialogFolderPicker Outlook VBA and Custom Forms 6
D Outlook 2016 Outlook not saving Sent Items Using Outlook 4
I Error saving screenshots in a custom form in outlook 2016, outlook 365 - ok in outlook 2013, outlook 2010 Outlook VBA and Custom Forms 5
I Saving attachments from multiple emails and updating file name Outlook VBA and Custom Forms 0
M Adding Subject to this Link-Saving VBA Outlook VBA and Custom Forms 5
D Saving Selected Emails as PDF and saving Attachments Outlook VBA and Custom Forms 6
B Saving items under a folder Using Outlook 3
R Quick Access view in File Explorer when saving attachments Using Outlook 0
N Saving And Deleting Outlook Attachments with Unknown Error Message Outlook VBA and Custom Forms 1
M Dialog called up multiple times when saving emails from macro Outlook VBA and Custom Forms 2
A saving attachement to folder named the same as rule name Outlook VBA and Custom Forms 0
T Saving all email to file folder in Windows Using Outlook 2
J Saving attachments from specific sender (phone number) to specific folder on hard drive Using Outlook 3
C Saving Outlook attachments and links to attachments with VBA Outlook VBA and Custom Forms 2
Kevin H Remotely saving emails Using Outlook 1
R Outlook 2010 Modify Style "Do not check spelling or grammar" not saving Outlook VBA and Custom Forms 0
R Outlook Office 365 not saving addresses Using Outlook 0
A Keep color categories when saving vCards Using Outlook 1
P Saving All Messages to the Hard Drive Using VBA Outlook VBA and Custom Forms 5
e_a_g_l_e_p_i question about saving my .pst so I can import it to my Outlook after I build a new system Using Outlook 10
S Editing an email with notes and saving it for record using Macro Outlook VBA and Custom Forms 3
O Saving Attachments to folder on disk and adding Initials to end of file name Outlook VBA and Custom Forms 9
J Outlook 2013 crashes saving VBA & clicking tools | digital signature Outlook VBA and Custom Forms 1
bifjamod Saving sent email to specific folder based on category with wildcard Outlook VBA and Custom Forms 1
N Saving .msg as sent item on send Outlook VBA and Custom Forms 1
erichamion Changes to meeting body not properly saving Outlook VBA and Custom Forms 4
A ItemAdd on Imap Folder get endless loop after saving item Using Outlook 5
T Saving Outlook 2010 email with attachments but read the email without Outlook Using Outlook 2
T From Field Blank when saving to folder other than Sent items Using Outlook 2
L Outlook DST (Daylight Saving Time) problem Using Outlook 0
F Using Outlook 2007 as an IMAP Mail Station Without Saving Data Locally Using Outlook 2
E Saving Changes To Edited E-Mail Received Message Using Outlook 0
D File Lock issue when saving message from Outlook to new folder Using Outlook 1
D Remove extension while saving attachments Using Outlook 1
K Printing & Saving Outlook Contacts Using Outlook 3
S Not saving attachments in the Sent Folder Using Outlook 2
S trouble with Outlook 2010 saving sent emails Using Outlook 2
D Saving outlook emails in html and attachments Using Outlook 4
W Default Saving a message as text Using Outlook 2
R Outlook 2007 QAT buttons not saving Using Outlook 2
C Exchange 2003 - Outlook 2003 - Calendar entries saving over each other Using Outlook 2
J Saving Published Outlook Form as msg Using Outlook 1
J Saving recent colors used for fonts in an email? Using Outlook 1

Similar threads

Back
Top