Microsoft KB Archive/171603: Difference between revisions
m (Text replacement - ">" to ">") |
m (Text replacement - """ to """) |
||
Line 62: | Line 62: | ||
<li>Open a Standard EXE project in Visual Basic.</li> | <li>Open a Standard EXE project in Visual Basic.</li> | ||
<li>Select References from the Project menu.</li> | <li>Select References from the Project menu.</li> | ||
<li>Select | <li>Select "Microsoft Outlook 8.0 Object Library" (msoutl8.olb), and click OK.</li> | ||
<li>Select Project1 Properties on the Project menu and set the Startup Object to | <li>Select Project1 Properties on the Project menu and set the Startup Object to "Sub Main".</li> | ||
<li>Select Add Module from the Project menu to add a module to the project.</li> | <li>Select Add Module from the Project menu to add a module to the project.</li> | ||
<li><p>Add the following sample code to Module1:<br /> | <li><p>Add the following sample code to Module1:<br /> | ||
Line 75: | Line 75: | ||
Dim olMAPI As Outlook.NameSpace | Dim olMAPI As Outlook.NameSpace | ||
Dim Folder As Outlook.MAPIFolder | Dim Folder As Outlook.MAPIFolder | ||
Const FOLDER_TO_OPEN = | Const FOLDER_TO_OPEN = "Mailbox - John Doe" 'Modify as appropriate | ||
Set olMAPI = GetObject( | Set olMAPI = GetObject("", "Outlook.Application") _ | ||
.GetNamespa ce( | .GetNamespa ce("MAPI") | ||
Call PrintFolderNames(olMAPI.Folders(FOLDER_TO_OPEN), | Call PrintFolderNames(olMAPI.Folders(FOLDER_TO_OPEN), "->") | ||
Set olMAPI = Nothing | Set olMAPI = Nothing | ||
End Sub | End Sub | ||
Line 86: | Line 86: | ||
Dim i As Integer | Dim i As Integer | ||
If tempfolder.Folders.Count Then | If tempfolder.Folders.Count Then | ||
Debug.Print a$ & | Debug.Print a$ & " " & tempfolder.Name & " "; | ||
Debug.Print tempfolder.UnReadItemCount | Debug.Print tempfolder.UnReadItemCount | ||
For i = 1 To tempfolder.Folders.Count | For i = 1 To tempfolder.Folders.Count | ||
Call PrintFolderNames(tempfolder.Folders(i), a$ & | Call PrintFolderNames(tempfolder.Folders(i), a$ & "->") | ||
Next i | Next i | ||
Else | Else | ||
Debug.Print a$ & | Debug.Print a$ & " " & tempfolder.Name & " "; | ||
Debug.Print tempfolder.UnReadItemCount | Debug.Print tempfolder.UnReadItemCount | ||
End If | End If |
Revision as of 11:05, 21 July 2020
Article ID: 171603
Article Last Modified on 2/12/2007
APPLIES TO
- Microsoft Visual Basic 5.0 Control Creation Edition
- Microsoft Visual Basic 5.0 Learning Edition
- Microsoft Visual Basic 6.0 Learning Edition
- Microsoft Visual Basic 5.0 Professional Edition
- Microsoft Visual Basic 6.0 Professional Edition
- Microsoft Visual Basic 5.0 Enterprise Edition
- Microsoft Visual Basic 6.0 Enterprise Edition
- Microsoft Outlook 97 Standard Edition
This article was previously published under Q171603
SUMMARY
The following code sample demonstrates how to determine the count of all unread messages on a per folder basis for all folders grouped under a specified Microsoft Outlook folder. The sample assumes that the Microsoft Outlook mail client is installed.
MORE INFORMATION
The code below uses a recursive routine to iterate through a mail folder to produce a list of all its sub-folders and a count of corresponding unread messages. The data is then displayed in the Visual Basic Immediate Window. The code takes advantage of the UnReadItemCount property of the Outlook MAPIFolder object.
- Open a Standard EXE project in Visual Basic.
- Select References from the Project menu.
- Select "Microsoft Outlook 8.0 Object Library" (msoutl8.olb), and click OK.
- Select Project1 Properties on the Project menu and set the Startup Object to "Sub Main".
- Select Add Module from the Project menu to add a module to the project.
Add the following sample code to Module1:
NOTE: Modify the FOLDER_TO_OPEN constant as appropriate.Sample Code
Option Explicit Private Sub Main() Dim olMAPI As Outlook.NameSpace Dim Folder As Outlook.MAPIFolder Const FOLDER_TO_OPEN = "Mailbox - John Doe" 'Modify as appropriate Set olMAPI = GetObject("", "Outlook.Application") _ .GetNamespa ce("MAPI") Call PrintFolderNames(olMAPI.Folders(FOLDER_TO_OPEN), "->") Set olMAPI = Nothing End Sub Sub PrintFolderNames(tempfolder As Outlook.MAPIFolder, a$) Dim i As Integer If tempfolder.Folders.Count Then Debug.Print a$ & " " & tempfolder.Name & " "; Debug.Print tempfolder.UnReadItemCount For i = 1 To tempfolder.Folders.Count Call PrintFolderNames(tempfolder.Folders(i), a$ & "->") Next i Else Debug.Print a$ & " " & tempfolder.Name & " "; Debug.Print tempfolder.UnReadItemCount End If End Sub
- Run the program.
RESULT: The unread message count for the folder FOLDER_TO_OPEN appears in the Immediate Window.
Keywords: kbhowto KB171603