Outlook Selection object

M

Michael Tissington

I'm seeing a strange issue with the Outlook Selection Object.
It seems that once I reference an item in the Selection object then that
object remains open until I release the Selection object.

For example (in brief)

Set Selections = ActiveExplorer.Selection

For Each Contact in Selections
Debug .Print Contact.FullName
Contact.Close
Set Contact = Nothing
' at this point the contact is still open
Next

Set Selections = Nothing ' this closes all the referenced Contacts

Is this by design or am I missing something .....

How do I force the Contact to be closed?
 
S

Sue Mosher [MVP-Outlook]

Have you tried leaving out the Close statement completely? If you aren't
opening it, you shouldn't need to close it.
 
M

Michael Tissington

Yes, I added the close to see if it would fix it ....

After playing a little more what seems to work is if I don't cache the
Selection object

For X = 1 To ActiveExplorer.Selections.Count
Set Contact = ActiveExplorer.Selections.Item(X)
Debug .Print Contact.FullName
Contact.Close
Set Contact = Nothing
Next

But this is slow :(

--
Michael Tissington
http://www.oaklodge.com
http://www.tabtag.com
 
D

Dmitry Streblechenko \(MVP\)

Yes, that's a big problem with the Selection collection: once you touch it
(even if you only need a count) it loops through all the items and
initializes them.
A particularly nasty side-effect of this sloppy behavior is that it makes it
extremely easy to run out of the 255 RPC channels/process limit.

Dmitry Streblechenko (MVP)
http://www.dimastr.com/
OutlookSpy - Outlook, CDO
and MAPI Developer Tool
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top