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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Using UnReadItemCount in Outlook 2003 2

Status
Not open for further replies.

PJFry

Technical User
Feb 6, 2005
93
0
0
US
I am looking for a way to count the unread items in an outlook folder and have the subject and date received written to a text file. I have seen the UnReadItemCount used to give the count in a message box, but I am not sure how to use it to write the above data to a file.

Suggestions?

Thanks in advance,
PJ
 
What have you tried so far and where in your code are you stuck ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
Here is what I currently have

Code:
Sub CountUnread()


Dim myOlApp
Dim myOlNameSpace
Dim objFolder
Dim itms
Dim ItemCount, UnReadItemCount


Set myOlApp = CreateObject("Outlook.Application")
Set myOlNameSpace = myOlApp.GetNamespace("MAPI")
Set objFolder = myOlNameSpace.GetDefaultFolder(6)
Set itms = objFolder.Items
UnReadItemCount = objFolder.UnReadItemCount

MsgBox "There are " & UnReadItemCount & " unread messages in your mailbox."

End Sub

As you can see, only counts the unread items. I would like to be able to export the subject and date for each of the unread items. Hmmmm, now that I am typing this I see that I am going down the wrong path. [Thinking out loud] The UnReadItemCount function does not appear the correct function. What I really need to do is scrape the folder for all of the unread items and pass the subject and date a text file. [Done thinking]

Any thoughts on how to do that?
Thanks for allowing the re-direct...
PJ
 
Are you aware that each MailItem object has an Unread property ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
And there you go.
Code:
[COLOR=red]' other stuff...[/color red]
Dim oMailItem As MailItem

For Each oMailItem In objFolder
  If oMailItem.Unread = True Then
     [COLOR=red]' write oMailItem.Subject and
     ' date to file
     ' Date can be formatted
     ' eg. Format(myMailItem.ReceivedTime, "dd-mm-yyyy")[/color red]
  End If
Next

Gerry
My paintings and sculpture
 
I ended up going with the code below that I pieced together from other sources and little common sense. My last question is how to point the code other Inboxes. There are five Inboxes that I want to run this on. For example on is call 'Mailbox - PIC'. What is the proper way to do that?
Code:
Sub Rescissions()
    Dim vFolder As MAPIFolder, vItem As Object
    Dim vFF As Long, vFile As String
    vFile = "S:\Contracts\!2nd_level_dash\Rescissions.txt"
     
    'GetFirst returns the "Outlook Today" folder
 Set vFolder = Application.Session.[COLOR=red]GetDefaultFolder(olFolderInbox)[/color]
    If vFolder.Items.Count = 0 Then Exit Sub 'empty folder
    vFF = FreeFile
    For Each vItem In vFolder.Items
        If TypeName(vItem) = "MailItem" Then
            If vItem.UnRead = True Then
                Open vFile For Append As #vFF
                Print #vFF, vItem.Subject & vbTab & Format(vItem.ReceivedTime, "mm/dd/yyyy")
                Close #vFF
            End If
        End If
    Next
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top