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
R Roadrunner Email Problems | Roadrunner Technical Service Number Outlook VBA and Custom Forms 0
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 0
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 2
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
V Can one change the formatting of email title blocks? Using Outlook 0
P default font when sending email from browser Using Outlook 1
D VBA Macro to Print and Save email to network location Outlook VBA and Custom Forms 1
B IMAP server rejects sent email - cannot deliver messages Using Outlook 2
TedSch Small vba to kill political email Outlook VBA and Custom Forms 3
X Open Hyperlinks in an Outlook Email Message (Help with Diane's solution) Outlook VBA and Custom Forms 3
e_a_g_l_e_p_i Email notifications changed with Outlook 2021 Using Outlook 8
glnz How to retrieve or redo Verizon.net email password without affecting Outlook connection? Using Outlook 1
Z Copy specific email body text Outlook VBA and Custom Forms 0
M Outlook 365 refuses to send email Using Outlook 1
B Search and Find Email by Folder Name Outlook VBA and Custom Forms 2
K Closing external IMAP email... Outlook 2013 Using Outlook 0
L Capture email addresses and create a comma separated list Outlook VBA and Custom Forms 5

Similar threads

Top