Consulting

Results 1 to 5 of 5

Thread: How many emails in the inbox folder

  1. #1
    VBAX Regular
    Joined
    Mar 2005
    Posts
    13
    Location

    How many emails in the inbox folder

    [VBA]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[/VBA]


    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?

    Thanks

    dillon
    Life is so much better when we can learn from each other.

  2. #2
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    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...
    K :-)

  3. #3
    VBAX Regular
    Joined
    Mar 2005
    Posts
    13
    Location
    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.

    dillon
    Life is so much better when we can learn from each other.

  4. #4
    VBAX Tutor
    Joined
    May 2004
    Location
    Germany, Dresden
    Posts
    217
    Location
    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.

    Daniel

  5. #5
    VBAX Master Killian's Avatar
    Joined
    Nov 2004
    Location
    London
    Posts
    1,132
    Location
    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
    K :-)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •