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,
 
M

Mara

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
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
B Outlook 2019 Custom Email form - Edit default email form Outlook VBA and Custom Forms 6
F Add a category before "Send an Email When You Add an Appointment to Your Calendar" Outlook VBA and Custom Forms 0
T Problem when requesting to view an email in a browser Using Outlook 0
J Outlook 365 Forward Email Subject to my inbox when new email arrive in shared inbox Using Outlook 0
HarvMan Archive Email Manually Using Outlook 1
L Fetch, edit and forward an email with VBA outlook Outlook VBA and Custom Forms 2
S New Email "From" box stopped working Using Outlook 0
Rupert Dragwater Duplicate email in Folder Using Outlook 7
M "Attachment Detacher for Outlook" add in, does it update the server copy of the email? Using Outlook 1
W Outlook 365 I am getting the "Either there is no default mail client" error when I try to send an email on excel Office 365 Using Outlook 1
MattC Changing the font of an email with VBA Outlook VBA and Custom Forms 0
L Specific Incoming Email Address Immediately Deleted Using Outlook 2
Witzker Outlook 2019 Macro to send an Email Template from User Defined Contact Form Outlook VBA and Custom Forms 0
Witzker Outlook 2019 Edit contact from email does not open the user defined contactform Using Outlook 3
V Macro to mark email with a Category Outlook VBA and Custom Forms 4
R Roadrunner Email Settings | Contact Roadrunner Customer Support Outlook VBA and Custom Forms 1
D Gmail mail is being delivered to a different email inbox in Outlook App 2021 Using Outlook 2
A How Do I Setup My Optonline.Net Email Account? Outlook VBA and Custom Forms 1
H Preventing the 'email address fetch from Exchange' crashing email reading code Exchange Server Administration 0
D multiple email accounts - why do I have to choose the "from" account address?? Using Outlook 2
Wotme create email only data file Using Outlook 1
F Outlook 2016 Email with attachments not being received Using Outlook 3
J Outlook 2019 Regex email addresses from body Outlook VBA and Custom Forms 6
D Prompt to prefix subject line whenever sending an email Outlook VBA and Custom Forms 3
J Quick steps delete original email and move reply/sent email to folder Using Outlook 2
C Wishlist Extract or scan new email addresses from out of office replies. Leads from OOO replies Using Outlook 1
T External email warning banner Outlook VBA and Custom Forms 0
A Links in email getting error message about group policy Using Outlook 4
richardwing Auto forward email that is moves into a specific outlook folder Outlook VBA and Custom Forms 5
J Recommendations for Outlook Duplicate Email Remover Using Outlook 6
Geldner Tweak Junk Email Reporting tool to default to particular email on send? Using Outlook 3
S Outlook 365 Can I change the possible range of highlighting colours when writing an Outlook email? Using Outlook 1

Similar threads

Top