Shazam
07-10-2009, 10:40 AM
Hi everyone,
I have this particular user sends me an email attachment into my subfolder of my inbox and I manually save the attachment into a file directory. How would I get this automated? I found this code below and when I tested it out the attachment does not get save. Am I missing something?
http://www.vbaexpress.com/forum/showthread.php?t=26780&highlight=Auto+save+attachments
I put this macro in the Outlook session module.
I'm using Outlook 2007 SP2.
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
Dim mai As Object
Dim strEntryIDs() As String
Dim lngEntryIDIndx As Long
Dim ns As Outlook.NameSpace
Dim mlItm As Outlook.MailItem
Dim atchmnt As Outlook.Attachment
Set ns = Outlook.Session
'You can get several mail items at a time:
strEntryIDs = Split(EntryIDCollection, ",")
'Loop through mail items:
For lngEntryIDIndx = 0 To UBound(strEntryIDs)
Set mai = ns.GetItemFromID(strEntryIDs(lngEntryIDIndx))
'Not all entry ids will be for Mail Items:
If TypeOf mai Is Outlook.MailItem Then
'You don't have to convert to a Mail Item object, I just prefer to
'so I can use the intellisense.
Set mlItm = mai
If LCase$(mlItm.SenderEmailAddress) = "emailaddress@home.com" Then
For Each atchmnt In mlItm.Attachments
'This will overwrite without prompting, watch it:
atchmnt.SaveAsFile "C:\Test\" & atchmnt.FileName
Next
End If
End If
Next
End Sub
I have this particular user sends me an email attachment into my subfolder of my inbox and I manually save the attachment into a file directory. How would I get this automated? I found this code below and when I tested it out the attachment does not get save. Am I missing something?
http://www.vbaexpress.com/forum/showthread.php?t=26780&highlight=Auto+save+attachments
I put this macro in the Outlook session module.
I'm using Outlook 2007 SP2.
Private Sub Application_NewMailEx(ByVal EntryIDCollection As String)
Dim mai As Object
Dim strEntryIDs() As String
Dim lngEntryIDIndx As Long
Dim ns As Outlook.NameSpace
Dim mlItm As Outlook.MailItem
Dim atchmnt As Outlook.Attachment
Set ns = Outlook.Session
'You can get several mail items at a time:
strEntryIDs = Split(EntryIDCollection, ",")
'Loop through mail items:
For lngEntryIDIndx = 0 To UBound(strEntryIDs)
Set mai = ns.GetItemFromID(strEntryIDs(lngEntryIDIndx))
'Not all entry ids will be for Mail Items:
If TypeOf mai Is Outlook.MailItem Then
'You don't have to convert to a Mail Item object, I just prefer to
'so I can use the intellisense.
Set mlItm = mai
If LCase$(mlItm.SenderEmailAddress) = "emailaddress@home.com" Then
For Each atchmnt In mlItm.Attachments
'This will overwrite without prompting, watch it:
atchmnt.SaveAsFile "C:\Test\" & atchmnt.FileName
Next
End If
End If
Next
End Sub