Senders email address in saved attachment

  • Thread starter Thread starter Mara
  • Start date Start date
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
e_a_g_l_e_p_i Need help updating email in Outlook 2021 Using Outlook 10
N Why does Outlook keeping adding to the email address I have in my notes portion of a contact? Using Outlook 2
P SPAM message about Comcast email migration to Yahoo Using Outlook 1
P anything new on the supposed shutdown of comcast.net email? Using Outlook 6
S Is there an add-in to PDF entire folders of email with Microsoft 365? Using Outlook 4
W frustrating trying to change email password Using Outlook 5
R File not found when sending email with attached pdf file Using Outlook 2
U Trouble sending large files to a email group but can to the individuals in that group Using Outlook 8
P Xfinity/Comcast email service stopping sometime in 2025 - warning Using Outlook 6
O Two identical email accounts in Offline Global Address List Using Outlook 2
H Spam email in Gmail not visible in Outlook Using Outlook 3
J Renegade spam URL line displayed in old local Outlook 365 email title Using Outlook 3
L Hide Selected Email Address from Address Book Using Outlook 5
Y QQ on Scheduled Delivery of an Email Using Outlook 0
T Replace Text in Email Subject Outlook VBA and Custom Forms 3
Rupert Dragwater Cannot reestablish gmail (email address) account in Outlook 365 Using Outlook 11
M Outlook 365 adding standard message in body of template email Outlook VBA and Custom Forms 3
E Create Rule to Forward Email if Subject Begins With Using Outlook 2
V iCloud For Windows v15.x - Missing Email Features ? Using Outlook 4
M Thunderbird email client - I wonder Using Outlook 1
D Outlook Desktop App Email Software Using Outlook 0
P Email and calendar entry text now shifts right about 3 tabs worth of space Using Outlook 1
J Outlook macro to run before email is being send Outlook VBA and Custom Forms 3
T Outlook 2010 Creating a email 'Group' in OL 2010 Using Outlook 2
D Send email from Outlook Alias using Mac? Using Outlook 7
T How to set Default FONT for Email composing ? Using Outlook 0
H Finding text in open email Outlook VBA and Custom Forms 12
T Why do Outlook Desktop 2021 tasks from my wife's email show up in my task pane? Using Outlook 2
A Opening a link from an email automatically Outlook VBA and Custom Forms 0
D Outlook 2021 New email reminder Using Outlook.com accounts in Outlook 1
Rupert Dragwater How do I remove an email ending with @gmail.com Using Outlook 4
M A plug in (or method) to keep email message formatting after it expires Using Outlook 1

Similar threads

Back
Top