View Full Version : How many emails in the inbox folder

04-10-2005, 04:23 PM
Private Sub CountInboxMessages()
'This procedure displays a message box that indicates the number of
'messages currently in the Inbox.
Dim objOutlook As Outlook.Application
Dim objNamespace As Outlook.NameSpace
Dim objMAPIFolder As Outlook.MAPIFolder
Set objOutlook = New Outlook.Application
Set objNamespace = objOutlook.GetNamespace(Type:="MAPI")
Set objMAPIFolder = objNamespace.GetDefaultFolder(olFolderInbox)
MsgBox "You have " & objMAPIFolder.Items.Count & _
" messages in your Inbox.", vbInformation
Set objMAPIFolder = Nothing
Set objNamespace = Nothing
Set objOutlook = Nothing
End Sub

Concerning the above, why does this script not run automatically? I use Outlook XP version, and when I receive my emails, the inbox states, how many unread emails I have. Would this script tell me how many emails in total, from the inbox folder?



04-10-2005, 05:30 PM
Hi dillon,
I wrapped your code in VBA tags to make it more readable. As for your question...
This code will bring up a message box saying how many mail items in total in your inbox.
If that's what you want, then to get it to run automatically, open the Outlook VBEditor (Alt+F11), add a new module and paste in this routine.
Now add a rule in Outlook (that applies to the conditions you want i.e. when a new mail comes in addressed to you) and the action for the rule needs to be "run a script". Click the underlined "script" link and select the name of the script you just added.
That would do it...

04-11-2005, 04:51 AM
Hello Killian:

the action for the rule needs to be "run a script". Click the underlined "script" link and select the name of the script you just added.

Concerning the above, are you stating that I need to amend the script, and place the amended script into the exsiting module?

I do not want a drop down message box, I would much prefer, to find the inbox folder using the Object Browser, and then amending the inbox folder to state total of emails, instead of emails not read.

I am out of my depth here, I am not sure if this is at all possible. I was reading the msdn.mirosoft, yesterday, I was trying to learn something new.

Much appreciated.


04-11-2005, 07:43 AM
Hi dillon,
you don't need to change the script. Just copy & paste it into any module in the Outlook-VBA-Editor (pick an existing or use the context-menu to create a new one).
To test the macro, place your curso right inside the code you just pasted and press F5. There should be no dropdown box as Outlook picks the Inbox automatically.
You should just get a messagebox telling you how many items (read + unread) you have in your inbox.


04-11-2005, 07:46 AM
I think you're talking about the number displayed next to the inbox???
To make this show the total number of mail items, right-click the inbox folder and select properties. On the general tab, you can choose whether to show the number of unread or total number of items.
If that's the case, no need for running scripts