How can I use VBA to do the same thing as Ctrl+Shift+B, Tools, Options, Custom and set a specific contact list as number one?
Asked
Active
Viewed 1,285 times
-1
-
Possible duplicate of [Change Outlook TO button behaviour](https://stackoverflow.com/questions/49061455/change-outlook-to-button-behaviour) ***(Same O.P.)*** – ashleedawg Mar 02 '18 at 15:58
2 Answers
2
You cannot do that in VBA - Outlook Object Model does not expose that functionality.
In Extended MAPI (C++ or Delphi), use IAddrBook.SetDefaultDir and set the PR_AB_CHOOSE_DIRECTORY_AUTOMATICALLY property appropriately.
If using Redemption (any language - I am its author) is an option, you can use the RDOAddressBook.DefaultAddressList
property:
set Session = CreateObject("Redemption.RDOSession")
Session.MAPIOBJECT = Application.Session.MAPIOBJECT
set AddrList = Session.AddressBook.AddressLists.Item("Contacts")
Session.AddressBook.DefaultAddressList = AddrList

Dmitry Streblechenko
- 62,942
- 4
- 53
- 78
-
I only have access to Outlook and VBA. I have no admin privileges to install any "extras". Appreciate anyway. – Duarte Botelho Feb 28 '18 at 21:46
-
You don't need admin privileges to install Redemption - it can install itself in HKCU when you register the dll with regsvr32.exe. – Dmitry Streblechenko Feb 28 '18 at 21:56
-
-
The free version shows a nag screen. The distributable version does not. – Dmitry Streblechenko Mar 01 '18 at 21:33
-
-
No, regsvr32 "full_path_to\redemption.dll" will be happy to install the dll in HKCU. – Dmitry Streblechenko Mar 01 '18 at 21:50
-
2
Is this what your trying to do?
Option Explicit
Public Sub Example()
Dim olDialog As SelectNamesDialog
Dim AL As AddressList
Set olDialog = Application.Session.GetSelectNamesDialog
Set AL = Application.GetNamespace("MAPI").AddressLists("Contacts")
Debug.Print AL.GetContactsFolder
With olDialog
.InitialAddressList = AL
.ShowOnlyInitialAddressList = True
.Display
End With
End Sub

0m3r
- 12,286
- 15
- 35
- 71
-
Well ... Not yet but I'm excited with the possibilities.. I want to do that but only when I'm creating an email And I press the button "TO". Does the "TO" Button have an event ? How can I use that function to replace that event ? – Duarte Botelho Mar 01 '18 at 21:26
-
No, there is no way to modify the address book dialog shown when you click the To button. Namespace.GetSelectNamesDialog only works if it is your code showing the dialog. – Dmitry Streblechenko Mar 01 '18 at 21:39