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 (e-mail address removed) & it'll be that e-mails Inbox i want to access
Thanks in advance
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 (e-mail address removed) & it'll be that e-mails Inbox i want to access
Thanks in advance