Close all open windows 
Author Message
 Close all open windows

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



Sat, 05 Feb 2005 03:39:51 GMT  
 Close all open windows
Try using a Do loop instead:

Do While myOutlook.Inspectors.Count > 0 Then
    Debug.Print myOutlook.Inspectors.Count
    myOutlook.Inspectors(1).Close olSave
Loop

--
Sue Mosher, Outlook MVP
Outlook and Exchange solutions at http://www.slipstick.com
Author of
     Microsoft Outlook Programming Jumpstart - coming September 2002
     http://www.slipstick.com/books/jumpstart.htm


Quote:
> 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



Mon, 07 Feb 2005 10:12:15 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. A97: Close all open windows

2. How to close all open windows

3. Q: detect closing and opening windows

4. Close All Open Windows

5. window.close()/window.open()

6. Determining if Exe is running, window has closed down, window has opened

7. closing the Yes/No window when closing a Shelled Window

8. Problems Closing a New Window using window.close()

9. Closing Parent Window when the child window closes

10. Window.Open(), then Window.close; how to test Window is closed?

11. Window.Open(), then Window.close; how to test Window is closed?

12. Close a DOS window opened by Shel()

 

 
Powered by phpBB® Forum Software