Tag Archives: outlook

Outlook Visual Basic For Applications (VBA)

Outlook: VBA code to display a random email from your inbox

Got loads of emails you need to action but don’t know where to start?  Run this outlook vba code or attach it to a menu item/button and it will display a randomly chosen email from your inbox.  I find this quite useful when I’m looking at the endless list of emails I don’t want to deal with – I just run the routine and make sure I deal with whatever email appears thrown at me.  It makes working through my email list more fun, too!


Sub ShowRandomEmails()

Dim myOLApp
Dim myNameSpace
Dim myFolder
Dim myItem

Set myOLApp = CreateObject("Outlook.Application")
Set myNameSpace = myOLApp.GetNamespace("MAPI")

Set myFolder = myNameSpace.GetDefaultFolder(olFolderInbox)

Dim intRandom
intRandom = Int(Rnd() * myFolder.Items.Count) + 1

Set myItem = myFolder.Items(intRandom)
myItem.Display

End Sub