A Microsoft Outlook email forum. Outlook Banter

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.

Go Back   Home » Outlook Banter forum » Microsoft Outlook Email Newsgroups » Outlook and VBA
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

To rename outlook mail attachment to sender's email address



 
 
Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1  
Old March 7th 06, 03:42 PM posted to microsoft.public.outlook.program_vba
sriramus
external usenet poster
 
Posts: 2
Default To rename outlook mail attachment to sender's email address

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
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
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
contact email field shows name not e-mail address. Why CajnBred Outlook - Using Contacts 1 January 20th 06 10:15 AM
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


All times are GMT +1. The time now is 05:14 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.Search Engine Friendly URLs by vBSEO 2.4.0
Copyright ©2004-2025 Outlook Banter.
The comments are property of their posters.