Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do i go through a folder in outlook and save the attachments ?

Outlook VBA

How do i go through a folder in outlook and save the attachments ?

by  Chance1234  Posted    (Edited  )
Code:
Function funGetEmailData(strFolder As String)
'strfolder is the name of the folder you want to look in
'dont forget to refernce oulook libaray if using in another 'app. 
 
Dim olOutlook As Outlook.Application
Dim ns As Outlook.NameSpace
Dim fld As Outlook.MAPIFolder
Dim itm As Object
Dim MyMail As Outlook.MailItem
Dim int_cnt As Integer
'-----------

On Error Resume Next




Set olOutlook = CreateObject("Outlook.Application")
Set ns = olOutlook.GetNamespace("MAPI")
Set itm = ns.GetDefaultFolder(olFolderInbox)
Set itm = itm.Folders(strFolder)

int_cnt = 1
For Each MyMail In itm.Items

MyMail.Attachments.Item(1).SaveAsFile "H:\Temp " & int_cnt & " "

int_cnt = int_cnt + 1

Next

For Each MyMail In itm.Items
MyMail.Delete
Next


Set olOutlook = Nothing
Set ns = Nothing
Set itms = Nothing
Set MyMail = Nothing

End Function
Register to rate this FAQ  : BAD 1 2 3 4 5 6 7 8 9 10 GOOD
Please Note: 1 is Bad, 10 is Good :-)

Part and Inventory Search

Back
Top