PDA

View Full Version : Opening a file while we save in certain folder



sathishesb
07-28-2011, 03:49 AM
Hi Guys,

I am using the below code to save all the attached files in the mail,

Sub test1()
Dim SubFolder As MAPIFolder
Dim Inbox As MAPIFolder
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
Set SubFolder = Inbox.Folders("reports")
If SubFolder.Items.Count = 0 Then
MsgBox "There are no messages in the Sales Reports folder.", vbInformation, "Nothing Found"
Exit Sub
End If
If SubFolder.Items.Count > 0 Then
For Each Item In SubFolder.Items
For Each Atmt In Item.Attachments
FileName = "C:\Report\" & Atmt.FileName
Atmt.SaveAsFile FileName
i = i + 1
Next Atmt
Next Item
End If
End Sub


the above code saves the file in the desired location at the same time i need to open the file as well.
please help me to open the attachment.
:help

JP2112
08-04-2011, 01:18 PM
See Open Any Email Attachment From Outlook (http://www.codeforexcelandoutlook.com/blog/2008/05/open-any-email-attachment-from-outlook/) for a method you can use to open any attachment you want.