-1

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?

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
  • 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 Answers2

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
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