![]() |
If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below. |
|
|
Thread Tools | Search this Thread | Display Modes |
|
#1
|
|||
|
|||
![]()
Hi All,
I want to rename my email attachment received to attachment name same as the sender address. In more detail: If my email is received from the address say " and the attachment name is "skills.doc" i want to extract the attachment and rename it from skill.doc to " Below is my code to save the attachment with the attached file name. and i want this attachement to renamed to what ever the variable strReport contains each time the loop runs. The below code that works fine: Sub SendersInFolder() Dim ns As Outlook.Namespace Dim Inbox As Outlook.MAPIFolder Dim Item As Outlook.MailItem Dim strReport As String Dim Atmt As Attachment Dim FileName As String Dim i As Integer ' Get the current Folder Set ns = GetNamespace("MAPI") Set Inbox = ActiveExplorer.CurrentFolder ' Check for messages in Folder If Inbox.Items.Count = 0 Then strReport = "No Mail Items in current Folder" Else For Each Item In Inbox.Items ' Get the Sender's name and Email address strReport = strReport & Item.SenderName & vbCrLf MsgBox strReport i = 0 For Each Atmt In Item.Attachments FileName = "D:\HR\Email Attachments\" & Atmt.FileName '#1 MsgBox FileName Atmt.SaveAsFile FileName '#2 i = i + 1 Next Atmt Next Item End If If i 0 Then MsgBox "I found " & i & " attached files." _ & vbCrLf & "I have saved them into the D:\HR\Email Attachments folder." _ & vbCrLf & vbCrLf & "Have a nice day.", vbInformation, "Finished!" Else MsgBox "I didn't find any attached files in your mail.", vbInformation, _ "Finished!" End If 'GetAttachments_err: 'MsgBox "An unexpected error has occurred." _ '& vbCrLf & "Please note and report the following information." _ '& vbCrLf & "Macro Name: GetAttachments" _ '& vbCrLf & "Error Number: " & Err.Number _ '& vbCrLf & "Error Description: " & Err.Description _ ', vbCritical, "Error!" ' Resume GetAttachments_exit GetAttachments_exit: Set Atmt = Nothing Set Item = Nothing Set ns = Nothing ' Clean Up Set Inbox = Nothing Set ns = Nothing Set Item = Nothing MsgBox "done" End Sub I tried modifying the above code in #1 as below line and tried FileName = "D:\HR\Email Attachments\" & strReport #2 Atmt.SaveAsFile strReport I am getting error which says Automation error Can anyone help me with this please Thanks in advance |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Thread Starter | Forum | Replies | Last Post |
To rename outlook mail attachment to sender's email address | sriramus | Outlook and VBA | 1 | March 7th 06 05:41 PM |
Sender's name and address is not displayed in Outlook 2003 | tezarin | Outlook - General Queries | 3 | February 24th 06 11:27 PM |
How to rename Global Address List? | TheTechie | Outlook - Using Contacts | 1 | February 21st 06 10:03 PM |
Set which local email account can send mail to contacts in address book. (associating an email address with a contact) | Scott Streit | Outlook - General Queries | 3 | January 27th 06 02:57 PM |
What is my Office Outlook Email address and how do I get the mail | literaryhaven | Outlook - General Queries | 1 | January 16th 06 03:00 PM |