I'm trying to write a small VB program to loop through and close all of the
open Outlook windows. I thought it would be really easy using the following
code, but I need to run it 3 or 4 times in order for it to close all of the
windows. I checked the Count property and it says the correct number. I also
tried iterating from 0 to Count - 1 but that didn't work either. It seems to
close all windows the first time that I'm replying to, but to close the
original messages I need to run it multiple times. Am I crazy?
Dim myMAPI As NameSpace
Dim myOutlook As New Outlook.Application
Dim myWindow As Outlook.Inspector
Dim Var As Integer
Set myMAPI = myOutlook.GetNamespace("MAPI")
If myOutlook.Inspectors.Count > 0 Then
Debug.Print myOutlook.Inspectors.Count
For Each myWindow In myOutlook.Inspectors
myWindow.Close olSave
Next
End If
Set myMAPI = Nothing
Set myOutlook = Nothing