Excel Change Focus to Outlook Contacts

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
 
C

Cole

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.
 

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