Excel Change Focus to Outlook Contacts

  • Thread starter Thread starter Cole
  • Start date Start date
C

Cole

Hi folks,

I've got code in Excel to see if there's an instance of Outlook
running. Problem is, whether it is running or not already, the last
command where I'm trying to change focus to Outlook Contacts creates a
new instance of Outlook Contacts. Any suggestions on what I'm missing?

Greatly appreciated!
-Cole - Here my code thus far:

' This is button to change focus to Outlook Contacts:

Dim ObjOutlook As Outlook.Application
Dim bWasntRunning As Boolean

bWasntRunning = False

On Error Resume Next
' Try first to use an existing instance.
Set ObjOutlook = GetObject(, "Outlook.Application")

If Err Then ' Outlook isn't running, so start it.
bWasntRunning = True
Set ObjOutlook = CreateObject("Outlook.Application")
End If

Set objnamespace = ObjOutlook.GetNamespace("MAPI")

' Next line does set objFolder to "Contacts"

Set objFolder = objnamespace.GetDefaultFolder(olFolderContacts)

' Then this next line is what opens a new instance of Outlook, even if
Contacts are already open.

objFolder.Display
 
This (objFolder.Visible=True) did not work. In the Watch window, it
shows Value is Out of context.

I've tried everything I could think of. Any further help would be
greatly appreciated. Thx.
 
Back
Top