Display Contacts

T

ttempl

My vb.net app currently has a button for Outlook Contacts that sets focus to
Outlook, specifically the Contacts tab. Can I programmatically set focus to a
specific address book on the Contacts tab? I know I could physically set each
workstation using the "Show this address book first". But, the users could
change that. So, can I set focus to the correct address book from my app?
For example, my company has a global address list with all employees in it,
and I want to set focus to that address book instead of the user's personal
address book.

Current code

Dim olApp As Outlook.Application
Dim oNS As Outlook.NameSpace

olApp = CreateObject("Outlook.Application")
oNS = olApp.GetNamespace("MAPI")
If olApp.ActiveWindow Is Nothing Then

oNS.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts).Display()
Else
oNS.Application.ActiveExplorer.CurrentFolder =
oNS.Application.ActiveExplorer.Session.GetDefaultFolder(Outlook.OlDefaultFolders.olFolderContacts)
End If
oNS.Application.ActiveExplorer.WindowState =
Outlook.OlWindowState.olNormalWindow
oNS.Application.ActiveExplorer.Left = 215
oNS.Application.ActiveExplorer.Top = 87
oNS.Application.ActiveExplorer.Width = 800
oNS.Application.ActiveExplorer.Height = 627
oNS.Application.ActiveExplorer.Activate()
olApp = Nothing
 
S

Sue Mosher [MVP-Outlook]

I'm not sure what you mean by "the Contacts tab" or "a specific address book
on the Contacts tab." Furthermore, the Global Address List doesn't display in
the main (Explorer) window in Outlook at all. If you're trying to display a
specific contacts folder in Outlook's main window, once your code returns
that folder, use it to set the value of ActiveExplorer.CurrentFolder. If
that's not what you're trying to do, please provide more details and include
your version of Outlook.
 
T

ttempl

Sorry, Sue. I was afraid I wouldn't explain myself well. We are using Outlook
Express 2007. I see what you mean... the Global Address List doesn't display
in the main window at all. I'm getting myself confused with terminology
between My Contacts and the Address Book.

I think what we want is to display the Global Address List. Manually, I can
go to Tools --> Address Book and choose the proper "Show names from the..."
drop down. I need to know how to do that programmatically if it is possible.
 
S

Sue Mosher [MVP-Outlook]

I'm still confused. There is no such thing as "Outlook Express 2007." Do you
mean Outlook 2007? If so, are you just trying to display the address book
programmatically for the user to select names from it? Display it, but not
for selection? Change the user's default address list?
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
T

ttempl

Obviously, I'm learning as I go and am a bit of a middleman on this one.
Sorry, yes, Outlook 2007.
Yes, just displaying the address book, so the user can view phone numbers
and such. Display it, but not for selection. There would be a button in my
app called "Company Directory" for example, that would get the user to the
GAL to view address and phone numbers.

Will this code get me close?
Dim outApp As Object, outNS As Outlook.NameSpace
Dim myAddressList As Outlook.AddressList

outApp = CreateObject("Outlook.Application")
outNS = outApp.GetNamespace("MAPI")
myAddressList = outNS.Session.AddressLists("Global Address List")

outNS.Application.ActiveExplorer.CurrentFolder = myAddressList

outApp = Nothing
 
S

Sue Mosher [MVP-Outlook]

No, that's the sort of code you'd use to work with the GAL programmatically.
There is no specific method in the Outlook object model for displaying the
address book for viewing not selection. You can, however, use the CommandBars
techniques to execute any toolbar command, including Tools | Address Book.
See http://www.outlookcode.com/d/tips/commandbarfun.htm. The ID for that
command is 353. There is no option in the Outlook object model for displaying
a specific address list using that technique.

If you want to display the address list for selection, however, you can use
the Namespace.GetSelectNamesDialog method to return a SelectNamesDialog
object and set its InitialAddressList and other useful properties. Maybe that
will suit your application better.

If neither of those solutions works for you, then the obvious alternative is
to build your own Windows form display whatever you want users to see.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 
S

Sue Mosher [MVP-Outlook]

No, that's the sort of code you'd use if you wanted to build your own Windows
form from the data in the GAL.

The closest thing the Outlook object model has to offer you is the
Namespace.GetSelectNamesDialog method, which returns a SelectNamesDialog
object whose various properties you can set. This is a dialog for selection,
not just viewing, but it's the only way available to control what address
list the user sees.
--
Sue Mosher, Outlook MVP
Author of Microsoft Outlook Programming: Jumpstart
for Administrators, Power Users, and Developers
 

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