![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
#1
|
|||
|
|||
![]()
Hi,
I'm currently using the below VBA to export all email attachments into one folder. I however also need to capture the senders email address, preferrably in the file name of the saved attachment. Is this possible or are you able to advise another solution to capture this information? 'DieseOutlookSitzung Public Sub LoopMailFolderByFolderPath() On Error GoTo ERR_HANDLER Dim oFld As Outlook.MAPIFolder Dim obj As Object Set oFld = GetFolder("Mailbox - ! TSN Credit Approvals\testing") If Not oFld Is Nothing Then For Each obj In oFld.Items If TypeOf obj Is Outlook.MailItem Then SaveAttachments obj End If Next End If Exit Sub ERR_HANDLER: MsgBox Err.Description, vbExclamation End Sub Public Function GetFolder(strFolderPath As String) As Outlook.MAPIFolder ' ' Author: Sue Mosher ' Dim objNS As Outlook.NameSpace Dim colFolders As Outlook.Folders Dim objFolder As Outlook.MAPIFolder Dim arrFolders() As String Dim I As Long On Error Resume Next strFolderPath = Replace(strFolderPath, "/", "\") arrFolders() = Split(strFolderPath, "\") Set objNS = Application.Session Set objFolder = objNS.Folders.Item(arrFolders(0)) If Not objFolder Is Nothing Then For I = 1 To UBound(arrFolders) Set colFolders = objFolder.Folders Set objFolder = Nothing Set objFolder = colFolders.Item(arrFolders(I)) If objFolder Is Nothing Then Exit For End If Next End If Set GetFolder = objFolder Set colFolders = Nothing Set objNS = Nothing End Function Public Sub SaveAttachments(ByRef olMail As Outlook.MailItem) On Error Resume Next Dim olAtt As Outlook.Attachment Dim sPath As String Dim sName As String sPath = "C:\Documents and Settings\c887954\My Documents\My Documents\NEW OMR Stuff for Mara\CAS\CAS emailed\" sPath = sPath & Format(olMail.ReceivedTime, "yyyymmdd_hhnnss_", vbMonday, vbFirstJan1) For Each olAtt In olMail.Attachments sName = olAtt.FileName 'ReplaceCharsForFileName sName, "_" olAtt.SaveAsFile sPath & sName Next End Sub Private Sub ReplaceCharsForFileName(ByRef sName As String, sChr As String) sName = Replace(sName, "/", sChr) sName = Replace(sName, "\", sChr) sName = Replace(sName, ":", sChr) sName = Replace(sName, "?", sChr) sName = Replace(sName, Chr(34), sChr) sName = Replace(sName, "", sChr) sName = Replace(sName, "", sChr) sName = Replace(sName, "|", sChr) End Sub '/DieseOutlookSitzung Thankyou, |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
Senders email address is saved attachment | Mara | Outlook and VBA | 0 | February 22nd 10 02:45 AM |
message attachment saved by Outlook.Attachment.SaveFileAs not open | arcfan | Add-ins for Outlook | 7 | May 12th 09 07:15 PM |
Send Saved Word Doc as attachment to fixed email address | Jules[_2_] | Outlook - General Queries | 0 | June 2nd 08 05:51 AM |
how to remove friend's email address from blocked senders list | Sahara | Outlook - Using Contacts | 1 | April 20th 08 05:08 PM |
Where are rules & Safe/Blocked Senders are saved in the registry? | [email protected] | Outlook - General Queries | 6 | July 3rd 07 09:52 AM |