Senders email address in saved attachment

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,
0
Utf
2/22/2010 2:47:01 AM
outlook.program_vba 490 articles. 0 followers. Follow

1 Replies
509 Views

Similar Articles

[PageSpeed] 13

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
> '
> ' 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,
0
Utf
2/22/2010 6:43:01 AM
Reply:

Similar Artilces:

How to use outlook address in Excel
Hello, I have an Excel sheet which I use as an invoicing-application. I would like to retrieve address-data from Outlook where I keep all my contact-data of my customers. So, I want to select a customer from my Outlook contactlist when I am writing a new invoice in Excel. In Word, I have a macro which does this, but unfortunately the Application.GetAddress does not work in Excel. Can somebody help me ? "Henny Slokker" wrote: > Hello, > > I have an Excel sheet which I use as an invoicing-application. I would like > to retrieve address-data from Outlook where I...

Unable to create email rules! Any suggestions...??
Hi, I would like to create a rule for Outlook 2003 email, but I find no "rules and alerts" option under the "Tools" menu. It is entirely absent, not grayed out. (When I've looked up how to create a rule, it states you click on "rules and alerts" under "Tools") Would appreciate suggestions. Do you have a mail account installed? Are you in the in-box when you look for this option? -- Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. All unsolicited mail sent to my personal account will be deleted wi...

why can't I get outlook to send when I'm emailing a webpage?
Hi. When I try to email a webpage to someone, Outlook immediately opens with the email template but it is always missing the send button and there is no option under actions to send it either. What is going on? Thanks!!! If you tell us your Outlook version and Windows version, and exactly what you're doing to send the page, then you'll have a better chance of getting a response. The Internet Explorer version might also be helpful. -- TechieBird http://bwain-dump.blogspot.com "reinadelmar" wrote: > Hi. When I try to email a webpage to someone, Outlook immediately...

End user wants to create items in Global Address List
I have an end user who wants to be able to create distribution lists and entries in the global address list. Any idea how I can configure him to do this? Douglas he would have to have Exchange permissions, and that isn't a particularly good idea... "Douglas McIver" <douglas@nospam.com> wrote in message news:OFGd$QhiEHA.1104@TK2MSFTNGP10.phx.gbl... > I have an end user who wants to be able to create distribution lists and > entries in the global address list. Any idea how I can configure him to do > this? > > Douglas > > ...

Problems with address books
I've had to re-install outlook '97 a couple of times to sort out some problems. Now I find that contacts isn't the default mail list. That's to say when I want to send an email the list of people is from an old address book and not from the contact list I have in front of me! How do I make sure that when I want to send an email or fax that I'm presented with a choice from my contact list? How can I safely delete the old address books which are now a waste of space? Peter ...

Shared/Group Email
I'm coming from having worked with FirstClass as an email and calendar system and had access to a shared group that all members of the organization could both post and read mail items in. Is there a way in Outlook that this can also be done? thanks "Jo-Anne" <Jo-Anne@discussions.microsoft.com> wrote in message news:FEA38DD5-1895-455B-BAA4-0D5FB8DE5D4A@microsoft.com... > I'm coming from having worked with FirstClass as an email and calendar > system > and had access to a shared group that all members of the organization > could > both ...

exporting to address book
I want to export address's from excell into address book for the mac. DIF is not available and have tried other formats to no avail. Anyone know how to do this. I have 1000 names, address's, phone numbers and email address's and wish to email to this group. Thanks Scotty Scotty I would look at either csv or txt output (File>Save as...), there are very few address books in the PC world certainly that don't offer these import formats -- HTH Nick Hodge Microsoft MVP - Excel Southampton, England www.nickhodge.co.uk nick_hodgeTAKETHISOUT@zen.co.uk.ANDTHIS "Scotty&...

Progress bar doesn't appear when saving
The progress bar doesn't display when saving a large document - even though we have the Status Bar on. We are using 2003 SP2 with the Adobe & LiveMeeting integrations. Even with disabling the integrations and removing macros, we cannot seem to get the progress bar back. any ideas? My support guy says to uninstall/reinstall Office to fix this, but with 67 users, I would rather not. khw ---------------------------------------- Hello? khw ---------------------------------------- "khw" wrote: > The progress bar doesn't display when saving a large document -...

2 accounts being sent under one address
I currently have two accounts in my Outlook 2000. xxx@provider.net & PPP@provider.net. The PPP@provider.net is the primary account. When sending an email from the xxx@provider.net, it still shows as the PPP@provider.net address, so in turn I get any replies to the xxx@provider.net back to the PPP@provider.net. Is there any way to make the reply address or the address of sender shown to the xxx@provider.net account? You said you had 2 accounts. You then listed 2 email addresses. Those are not the same thing. Clarify your post. -- Russ Valentine [MVP-Outlook] "jeepstr9" ...

Where can I delete an old/incorrect email address?
I'm using Outlook 2003 So I have, say, Sandy in my contacts book. Her email is SW@...... Later her email changes to SAW@...... I make the change in my contacts. But when I'm creating a new email and I start to type "Sandy..." in the TO field, it still finds the old "SW@..." address. Why? How can I delete that old & incorrect address forever? (Without starting from scratch and loosing all my old email?) Thanks Gary use arrow keys to highlight 'bad' address then hit delete btn "jabadoodle" <jabadoodle@yahoo.com> wrote in message n...

Some recipients get the attachment, some get winmail.dat
This one has me baffled. We are using Exchange 2000 and Outlook 2000 and have been for 8 months. No previous problems with attachments (.doc, .xls, .jpg). About 2 weeks ago, we started hearing from certain recipients that the attachment wasn't arriving; instead they were getting an unreadable file called winmail.dat. MS says that this is because the sender is using Rich Text to format the email. We have changed the senders to use Plain Text and still have the same problem. If the email is sent to several recipients, some will get the attachment fine, some will not. This didn'...

Size Limitations for Attachments send with Outlook E-Mail
Any attachment larger than 100 kb does not send when attempted using Outlook 2003. Please advise as to how one can adjust the size limits for outgoing attachments? Thank you. "Tim" <tgregoire@craneandhoistsales.com> wrote in message news:080201c3dea4$4a835670$a401280a@phx.gbl... > Any attachment larger than 100 kb does not send when > attempted using Outlook 2003. Please advise as to how > one can adjust the size limits for outgoing attachments? > Thank you. Have you checked that your ISP and/or system admin haven't put a limit on? ...

how do I set up my email with outlook
I have just installed outlook but I can send emails form outlook, what do I need to set up and to link to yahoo? tokyo gyoza wrote: > I have just installed outlook but I can send emails form outlook, > what do I need to set up and to link to yahoo? You have to pay Yahoo if you want to use it in Outlook (via POP). ...

the same outbound SMTP address for multible users
Hi group Her is a tricky one Is it possible to configure Microsoft Exchange 2003 recipients so the emails seems to be comming from the same sender SMTP address e.x. info@domain.com when the sends email outside the organisation (not internal) it must be done on the server level and not in Outlook using "From" field Thanks in advance B.Hansen MCP Denmark On Thu, 4 Jan 2007 21:25:12 +0100, "Bjarne Hansen" <bhansen1@hotmail.com> wrote: >Hi group > >Her is a tricky one >Is it possible to configure >Microsoft Exchange 2003 recipients so the emails see...

Undeliverable email message..._
My ISP migrated to a new smtp server and I had to make the necessary changes to relay my messages correctly. However, when I forward an e-mail or reply to a cashed mail address I receive the following: From: System Administrator Sent: Monday, October 04, 2004 4:26 PM To: email@domain.com Subject: Undeliverable:RE: Message Your message did not reach some or all of the intended recipients. Subject: RE: Message Sent: 10/4/2004 4:26 PM The following recipient(s) could not be reached: email@domain.com on 10/4/2004 4:26 PM You do ...

How to paste animation in publisher for an email message
In a MS Publisher document, I have pasted animated bmp & gif files. When I send the doc by MS Outlook email, the animation doesn't work when the message is pulled up. Is there a special way to paste & activate animation in Publisher? This is not an option in Publisher. Publisher automatically changes the animated images to normal images. -- Brian Kvalheim Microsoft Publisher MVP http://www.publishermvps.com This posting is provided "AS IS" with no warranties, and confers no rights. "Flyboy" <Flyboy@discussions.microsoft.com> wrote in message news:...

outlook 2003 missing emails offline
I am trying to setup a user with an offline folder in outlook 2003. The problem is it does not download all his emails. ON the server it shows he has 200 emails, but in his offline it is only 30. I checked and there is no filters or anything on it. I tried recreating his offline folders and everything, to no avail. Any suggestions? It looks like the emails he is missing are a month or so old, although he has older ones from a few years ago? Did you check to see which folders are set for offline synch? Is this user using Exchange Cached Mode? --� Milly Staples [MVP - Outlook] Post al...

Error saving Excel files in a network drive
I have a problem saving Excel files onto a network drive. I get an error saying it was imposible to save the file. It creates a temporary file and then I have to open it and save it as a new document. This issue doesn�t occur saving the file in my hard disk. This happens with "Full control" access to the shared folder... I have Windows XP and Office 2000. Thanks in advance Mateo. Hi Mateo, > I have a problem saving Excel files onto a network drive. I get an error > saying it was imposible to save the file. It creates a temporary file and > then I have to open it and sav...

Attachments not received #2
Can anyone help ? - When I send some attachments using Outlook 2003 the attachments are not received by the recipient just the mail. Incidentally they show the attachment paperclip in the Sent Items as if they were sent. This happened in earlier version too but only when I switched to XP. It does not occur with Outlook Express Many thanks First thing to check is your sending mail format. Make sure you're not using Rich Text Format. Try Plain Text or HTML instead "Marian Hughes" <moi@esatclear.ie> wrote in message news:OMWri8Y4DHA.1592@TK2MSFTNGP10.phx.gbl... >...

Vista stipping attachments
Can anyone please help me understand why my Vista home premium does not let any attachments through that I send home from work? The text part of the message comes through, but the attachment is gone. My wife's home computer uses XP and it can receive the messages ok. This appears to have started after I downloaded service pack 2 but that's only speculation on my part, my system once received work emails with no problem. Is it a POP3 account? Have you checked the message source, (Ctrl+F3), to see if the attachment is actually missing? Are you using e-mail scanning? ...

Can't open attachments in Outlook Express
I can't open attachments. I get the message; OE removed access to the following attachments iin your mail: ( the name of the attachment is shown. I sthis a virus thing. I have Norton Antivirus installed? Or is this a setting problem? I need some help ASAP as I have students who are depending on me for some answers Thank you very much Tim wrote: > I can't open attachments. I get the message; OE removed > access to the following attachments iin your mail: ( the > name of the attachment is shown. > > I sthis a virus thing. I have Norton Antivirus installed? > Or ...

Arrows in Email
When I receive text in some emails, the sentences are preceeded by arrows. Can someone tell me a little information about these arrows, like if I want to send the message to to someone else without arrows, and how do they get there in the first place? Gus Gus GusGus <charlieg@charter.net> wrote: > When I receive text in some emails, the sentences are preceeded by > arrows. Can someone tell me a little information about these arrows, > like if I want to send the message to to someone else without arrows, > and how do they get there in the first place? You are using...

Address Lists #4
This is a multi-part message in MIME format. ------=_NextPart_000_006A_01C524AC.4E5782E0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Does anyone know of a solution (MS, script or 3rd Party) to get the = 5000+ external contacts I have in public folders into an address list? = I know how to set that up on clients to display the public folder. Some = people need access to 5 or so different PF and we are looking at various = CRM solutions that would created more nested public folder contact = lists... just looking for another solutions...

pictures and graphics not displaying in emails
I used to always see pictures, logos, graphics, etc. in incoming emails from various companies whose newsletters or ads I subscribe to. Now there is just a box with an x in it. I have tried to change every option I thought might return things to the way they were, but with no luck. I believe this happened after I installed some updates to the Vista OS. Anyone else having this problem? Anyone know how to solve it? Thanks. Toole | Options | Security. Uncheck: "Block images...........". -- Bruce Hagen MS-MVP [Mail] Imperial Beach, CA ...

Outlook attachment?
A remote office is experiencing a problem with outllook. If they recieve a email, it also recieves an attachment consisting of a duplicate of the message. The attachment is something like ATT00010.TXT. This only happens with outlook (office 97 and 2000), with outlook express it works normally. Any suggestions? Here is the article with details on why the messages are not received correctly. The root cause would be a problem supporting MS Rich Text , or more specifically TNEF, somewhere along the message route. Simple fix would be to ask the sender to change format to either Plain Text ...