Senders email address in saved attachment

Status
Not open for further replies.
M

Mara

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

'

' 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,
 
Hi,

Managed to find the answer on previous "Excel Postings".

For those interested, I updated the code with:

olAtt.SaveAsFile MyPath & olMi.SenderName & ".xls"

"Mara" wrote:


> 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
> '
> ' 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,
 
Status
Not open for further replies.
Similar threads
Thread starter Title Forum Replies Date
O How to display senders email address (column) Using Outlook 1
Albert McCann Outlook 2021 Outlook Display of HTML Email from two senders is glitchy Using Outlook 0
D ISOmacro to extract active mail senders name and email, CC, Subject line, and filename of attachments and import them into premade excel spread sheet Outlook VBA and Custom Forms 2
A Add multiple servers "on behalf of" email to "safe senders" list. Using Outlook 1
S Send email via SMTP - use transport rules to add to senders inbox (then rule to move to sent items Exchange Server Administration 1
P Outlook 2010 sending safe senders email to junk box Using Outlook 8
C Outlook - Macro to block senders domain - Macro Fix Outlook VBA and Custom Forms 1
E Macro to block senders domain Outlook VBA and Custom Forms 1
M Automatically add senders first name to a greeting Outlook VBA and Custom Forms 1
D Change senders title Using Outlook 1
B Outlook - Mail from safe senders list being sent to Spam Folder Using Outlook 0
N Outlook 2010 Flag blocked for Safe Senders List???? Using Outlook 7
D Delete Emails from Senders in Shared Mailbox Outlook VBA and Custom Forms 1
N Outlook script to forward emails based on senders' address Outlook VBA and Custom Forms 2
Diane Poremsky Add to Safe (and Blocked) Senders for Users Using Outlook 0
J How to display senders name in inbox Using Outlook 2
Wotme VBA to block senders Outlook VBA and Custom Forms 1
J Outlook 2010 junks all message from internal senders Using Outlook 2
N Blocked senders list disappears Using Outlook 4
M A plug in (or method) to keep email message formatting after it expires Using Outlook 0
L VBA to Triage Incoming Email Outlook VBA and Custom Forms 0
R Legacy Outlook on Mac Email Cache Using Outlook 0
P Email address auto-completes work fine on laptop, but no longer on desktop Using Outlook 3
S Create Outlook Task from Template and append Body with Email Body Outlook VBA and Custom Forms 4
H Copying email address(es) in body of email and pasting in To field Outlook VBA and Custom Forms 1
A Search folder and move the email Outlook VBA and Custom Forms 0
P VBA to add email address to Outlook 365 rule Outlook VBA and Custom Forms 0
farrissf Outlook 2016 Optimizing Email Searches in Outlook 2016: Seeking Insights on Quick Search vs Advanced Search Features Using Outlook 0
D Delete selected text in outgoing email body Outlook VBA and Custom Forms 0
F Graphics in email / Mac recipient garbled Using Outlook 0
D Outlook VBA forward the selected email to the original sender’s email ID (including the email used in TO, CC Field) from the email chain Outlook VBA and Custom Forms 2
Witzker Outlook 2019 Macro to seach in all contact Folders for marked Email Adress Outlook VBA and Custom Forms 1
E Outlook 365 Save Selected Email Message as .msg File - oMail.Delete not working when SEARCH Outlook VBA and Custom Forms 0
S Email Macros to go to a SHARED Outlook mailbox Draft folder...NOT my personal Outlook Draft folder Using Outlook 2
R Outlook 365 VBA AUTO SEND WITH DELAY FOR EACH EMAIL Outlook VBA and Custom Forms 0
G Print email attachments when hit subfolder Outlook VBA and Custom Forms 1
C Spam Email? Using Outlook 2
G Automatically delete email when a condition is met Outlook VBA and Custom Forms 1
E Save Selected Email Message as .msg File - digitally sign email doesn't works Outlook VBA and Custom Forms 1
S Email was migrated from GoDaddy to Microsoft exchange. We lost IMAP ability Exchange Server Administration 1
R Outlook 365 How to integrate a third-party app with Outlook to track email and sms? Using Outlook 2
S Paperclip icon shows without attachment in email under Sent folder Using Outlook 0
B Outlook 2019 Automatically move email after assigning category Using Outlook 4
Rupert Dragwater How to permanently remove an email address Using Outlook 9
K vba code to auto download email into a specific folder in local hard disk as and when any new email arrives in Inbox/subfolder Outlook VBA and Custom Forms 0
F Auto changing email subject line in bulk Using Outlook 2
F Want to add second email to Outlook for business use Using Outlook 4
kburrows Outlook Email Body Text Disappears/Overlaps, Folders Switch Around when You Hover, Excel Opens Randomly and Runs in the Background - Profile Corrupt? Using Outlook 0
J Outlook 365 Outlook Macro to Sort emails by column "Received" to view the latest email received Outlook VBA and Custom Forms 0
A Outlook 2019 Help with forwarding email without mentioning the previous email sender. Outlook VBA and Custom Forms 0

Similar threads

Back
Top