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 gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

automate download of outlook attachments 1

Status
Not open for further replies.

PizMac

Programmer
Nov 28, 2001
90
GB
does anyone know if you can write code (in VB or anything else!) that can automate the dowbnload of an attachment - when a certain e-mail comes in the user would like to press a "button" and automatically have the attachment downloaded to a specified folder.
 
Thanks but...
We want to be able to use a pre-coded folder name and maybe write a bit of code to rename it..

Also - would be handy if it was automatic if the mail came from a specified address so there was no user involvment
 
This is the kind of thing I use. Add it to a vbs or vba program and run it when an email arrives or alternatively add it to scheduled tasks to check every now and then...

Dim mliNew As MailItem
Dim ns As NameSpace
Dim oOutlook As Outlook.Application


Set oOutlook = New Outlook.Application
Set ns = oOutlook.GetNamespace("MAPI")
Set mfrInbox = ns.GetDefaultFolder(olFolderInbox)



With mfrInbox
If .Items.Count = 0 Then
MsgBox "There are no messages in the Inbox.", vbInformation, "Nothing Found"
Else
.Items.Sort "Received", True
'check all e-mails sent today
For Each mliNew In .Items
If mliNew.sendername = "myfriend" Then
mliNew.Attachments.Item(1).SaveAsFile sMyNewFile
Else
Exit For
End If
Next
End If
End With

Main_Exit:
Set mliNew = Nothing
Set ns = Nothing
Set oOutlook = Nothing
Exit Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top