Read latest email

akhendre88

Board Regular
Joined
Sep 17, 2015
Messages
76
Hello,

I have written a macro to go to the specific folder in inbox and read the latest mail and display it via msgbox, however I am not able to do the 2nd part i.e reading the mail body and display it through msgbox. Below is my code,

Code:
Sub chnageFolder()
    Dim ns As Outlook.NameSpace
    Dim exp As Outlook.Explorer
    Dim myInbox As Folder, folder1 As Folder, folder2 As Folder
    Dim myOlItems As Outlook.Items
    Dim mItem As Outlook.mailItem
        
    Set ns = Application.GetNamespace("MAPI")
    Set exp = Application.ActiveExplorer
    
    'Accessing the Inbox
    Set myInbox = ns.GetDefaultFolder(olFolderInbox)
    
    'Changing the current folder from inbox to Data Alerts
    Set folder1 = myInbox.Folders.Item("Alerts").Folders.Item("Data Alerts")
    Set exp.CurrentFolder = folder1
    Set myOlItems = folder1.Items
    
    If (mItem.UnRead = "True") Then
        MsgBox mItem.Display
    End If
            
End Sub

Please suggest.

Thank you
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Hi,

Normally people copy mail content to a Word doc, though I have never done it.
However this appears to work. Though the formatting will be up the creek using a MsgBox and there's a content limit to think about.

Code:
  For Each mItem In folder1.Items
    
    If (mItem.UnRead = "True") Then
        copyMail = mItem.Body
        MsgBox (copyMail)
    End If
    Next
 
Upvote 0

Forum statistics

Threads
1,223,896
Messages
6,175,265
Members
452,627
Latest member
KitkatToby

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top