Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hi, i would like to have a macro 2

Status
Not open for further replies.

Adnane

Technical User
Apr 22, 2003
88
EU
Hi,

i would like to have a macro for Outlook that would allow me to go through all the mails within a specific folder and get all the sender's mail addresses, then put them in an Excel file.

Do you think that this can be done? and if yes i would really appreciate some help on doing this.

Regards,

Adnane
 
Just for S&G :)

Code:
Sub Emails_In_Inbox()
'***************************************************************
'* Set a refernce to the Outlook before running this procedure *
'*                                                             *
'*     This will list all of the emails in the Inbox onto the  *
'*     current sheet, be sure to have an empty sheet selected  *
'***************************************************************

' Variable Declaration
Dim inbox As Outlook.MAPIFolder, user As String
Dim i As Integer, mail As Integer, mails As Integer
Application.ScreenUpdating = False
Cells.Delete
' Headings
[A1] = "From": [B1] = "Subject": [C1] = "Attachments": [D1] = "Recieved"
With [A1:D1].Font
    .Bold = True
End With
Application.Calculation = xlCalculationManual
Set inbox = GetObject("", "Outlook.Application") _
        .GetNamespace("MAPI").GetDefaultFolder(olFolderInbox)
mails = inbox.Items.Count
i = 0: mail = 0
' Extract Email Information
Do While i < mails
    i = i + 1
    With inbox.Items(i)
        mail = mail + 1
        Cells(mail + 1, 1).formula = .SenderName
        Cells(mail + 1, 2).formula = .Subject
        Cells(mail + 1, 3).formula = .Attachments.Count
        Cells(mail + 1, 4).formula = Format(.ReceivedTime, &quot;dd.mm.yyyy hh:mm&quot;)
    End With
Loop
' Clean Up
Set inbox = Nothing
Columns(&quot;A:D&quot;).AutoFit
[A1].Select
With Application
    .Calculation = xlCalculationAutomatic
    .ScreenUpdating = True
End With
End Sub

This runs from Excel though, I wasn't sure if you wanted that or a macro from Outlook.

I hope this helps!


Peace! [peace]

Mike

Never say Never!!!
Nothing is impossible!!!
 
Thanks for the star Skip! [wavey]

Even though I spelled reference wrong! [blush]

:)

Have you read my post on Worksheet referencing yet? thread707-642389



Peace! [peace]

Mike

Never say Never!!!
Nothing is impossible!!!
 
Mike,

That's a really good tip. I don't use it often enough! I suppose that one should rigerously name all their objects from the generic default sequentially numbered object reference names.

Shows to go that an ol' coger kin lern a thin er two.

I'm givin' ya 'nuthr wun!

:)

Skip,
Skip@TheOfficeExperts.com
 
Thanks Mike, that works perfectly. i first thought of a macro running from Outlook but as long as this works it's ok for me. i don't mind from where it's launched.

Thanks again. you deserve a star!

Adnane
 
One last thing please Mike. what your macro outputs is the name of the sender. is there any way it could get the actual email address of the sender rather than it's name.
Do you see what i mean?

Thanks

Adnane
 
Hi Adnane,

The .SenderName property returns the From listing in the inbox, and if the sender has set their name up to be seen this way for messages received that is how it will show in the Inbox. I don't know of any other property (or way) to show the actual address, even though it is visible in the mail header upon viewing.

Sorry!



Peace! [peace]

Mike

Never say Never!!!
Nothing is impossible!!!
 
Wierd, I tried that and it didn't work! Maybe I should have checked harder! [blush]



Peace! [peace]

Mike

Never say Never!!!
Nothing is impossible!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top