Why Does GetObject Create New Instances of Outlook 2007+

R

rob

I'm using GetObject to automate an existing instance of Outlook using VBA fro
Excel to open the address book and allow the user to select a group o
recipients

When I do this with Outlook 2007 or 2010 an new Outlook window is opened eac
time the code is run. If I quit the instance of Outlook I'm holding the
Outloo
is shut down completely, regardless of how many windows are showing in th
TaskBar

Repro code is shown below. How can I get this to not open a new Outlook windo
each time it's run? Thanks

Sub ShowAddressList(

Dim objOutlook As Outlook.Applicatio
Dim objNameSpace As Outlook.NameSpac
Dim objDialog As Outlook.SelectNamesDialo
Dim objRecipient As Outlook.Recipien

Set objOutlook = GetObject(, "Outlook.Application"
Set objNameSpace = objOutlook.GetNamespace("MAPI"
Set objDialog = objNameSpace.GetSelectNamesDialo

objDialog.Displa

For Each objRecipient In objDialog.Recipient
Debug.Print objRecipient.Nam
Next objRecipien

Set objDialog = Nothin
Set objNameSpace = Nothin
Set objOutlook = Nothin

End Sub
 
R

rob

rob wrote on 06/07/2010 11:39 ET
I'm using GetObject to automate an existing instance of Outlook using VB fro
Excel to open the address book and allow the user to select a group o
recipients

When I do this with Outlook 2007 or 2010 an new Outlook window is opened eac
time the code is run. If I quit the instance of Outlook I'm holding the
Outlook is shut down completely, regardless of how many windows are showin i
the TaskBar

Repro code is shown below. How can I get this to not open a new Outloo windo
each time it's run? Thanks

Sub ShowAddressList(

Dim objOutlook As Outlook.Applicatio
Dim objNameSpace As Outlook.NameSpac
Dim objDialog As Outlook.SelectNamesDialo
Dim objRecipient As Outlook.Recipien

Set objOutlook = GetObject(, "Outlook.Application"
Set objNameSpace = objOutlook.GetNamespace("MAPI"
Set objDialog = objNameSpace.GetSelectNamesDialo

objDialog.Displa

For Each objRecipient In objDialog.Recipient
Debug.Print objRecipient.Nam
Next objRecipien

Set objDialog = Nothin
Set objNameSpace = Nothin
Set objOutlook = Nothin

End Su
This turned out to be a completely different problem than I thought it was, s
never mind this request. Thanks.
 

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