Problem in copying emails and its attachments into a folder

Joined
Aug 23, 2005
Messages
5
Reaction score
0
Hi,

I am new user to this and I am trying to find out a solution in copying emails and its attachments into a folder.

Please help me if you got the reply or if you already have it.

I am working to save in a folder the Outlook inbox messages and its attachements at once sequentially when I run the macro.
I am able to copy the attachments but I am not able to copy the message part i.e., .pst file i.e whole body of message that is received.

here is my code:

Sub GetAttachments()



On Error GoTo GetAttachments_err

Dim ns As NameSpace
Dim Inbox 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 = "H:\Email Attachments\" & _
Format(Item.CreationTime, "yyyymmdd_hhnnss_") & 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 into the H:\Email Attachments." _
& vbCrLf & vbCrLf & "Have a nice day.", 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

----------------------------------------------------------------------------------------------------------------------------------------

Moreover, If you can also help me how can I directly send to print in printer this files i.e messages and its attachments.

I will be greatful to you if you help me in this situation because I am doing this project from almost one month and still persisting with above problem.

Thanks in advance.

Santhosh.
 
Last edited:

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

Top