How to pause a macro when dialog box is open

First, I need to create a form which will automatically populate contact details from Outlook.  I have used http://www.msoutlook.info/  as a guide.  Now I want to create a macro which will automatically bring up this address book, have the user select a name from the contact list, and then reformat it by removing the spaces.

Problem I have is that as soon as the address book dialog box opens, I am not able to pause the macro so that the user can make the selection.

Any helpful tips on how I can automate this?  The end goal is that the user does not want to cut and paste the customer data from the address book into a form I am creating.  The link above seems to be the only way to select a contact from Outlook, but the user wants the form completely automated -- he doesn't want to have to remember how to call up the address book.


Take a look at the Contact List add-in that you can download from the following page of my OneDrive:

http://bit.ly/1hduSCB

Hope this helps,
Doug Robbins - MVP Office Apps & Services (Word)
dougrobbinsmvp@gmail.com
It's time to replace ‘Diversity, Equity & Inclusion’ with ‘Excellence, Opportunity & Civility’ - V Ramaswamy

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

You can call the Outlook address book directly from your procedure e.g.

Public Function SelectAddress() As String
Dim strCode As String
Dim strAddress As String

    'Set up the formatting codes in strCode
    strCode = "{<PR_DISPLAY_NAME_PREFIX> }<PR_GIVEN_NAME> <PR_SURNAME>" & vbCr
    strCode = strCode & "{<PR_TITLE>" & vbCr & "}"
    strCode = strCode & "<PR_COMPANY_NAME>" & vbCr
    strCode = strCode & "<PR_POSTAL_ADDRESS>"

    'Let the user choose the name in Outlook
    strAddress = Application.GetAddress("", _
                                        strCode, False, 1, , , True, True)
    If strAddress = "" Then
        MsgBox "User cancelled or no address listed", , "Cancel"
    End If
    SelectAddress = strAddress
End Function

SelectAddress is the selected address e.g.


Sub Test()
MsgBox SelectAddress
End Sub

Graham Mayor (Microsoft Word MVP 2002-2019)
For more Word tips and downloads visit my web site
https://www.gmayor.com/Word_pages.htm

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

You can call the Outlook address book directly from your procedure e.g.

Public Function SelectAddress() As String
Dim strCode As String
Dim strAddress As String

    'Set up the formatting codes in strCode
    strCode = "{<PR_DISPLAY_NAME_PREFIX> }<PR_GIVEN_NAME> <PR_SURNAME>" & vbCr
    strCode = strCode & "{<PR_TITLE>" & vbCr & "}"
    strCode = strCode & "<PR_COMPANY_NAME>" & vbCr
    strCode = strCode & "<PR_POSTAL_ADDRESS>"

    'Let the user choose the name in Outlook
    strAddress = Application.GetAddress("", _
                                        strCode, False, 1, , , True, True)
    If strAddress = "" Then
        MsgBox "User cancelled or no address listed", , "Cancel"
    End If
    SelectAddress = strAddress
End Function

SelectAddress is the selected address e.g.


Sub Test()
MsgBox SelectAddress
End Sub

Unfortunately, I don't do programming - this is all Latin to me!  Do I just cut and paste, and if so, where?

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

Take a look at the Contact List add-in that you can download from the following page of my OneDrive:

http://bit.ly/1hduSCB

I get a Run time error 438: "Object doesn't support this property or method"

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

This is a Word function. http://www.gmayor.com/installing_macro.htm   

You said you wanted to create a macro - I assumed that you might know how to do that.

The function gets the name and address from the Outlook address book. How you use that would depend on what exactly you are trying to do with the form. You simply call the function from your macro as in the Test macro which simply displays the selected address in a message box. To type it at the cursor change the line MsgBox SelectAddress to

Selection.Text = SelectAddress

Tell us more about the 'form' and I will be more specific.

Graham Mayor (Microsoft Word MVP 2002-2019)
For more Word tips and downloads visit my web site
https://www.gmayor.com/Word_pages.htm

Was this reply helpful?

Sorry this didn't help.

Great! Thanks for your feedback.

How satisfied are you with this reply?

Thanks for your feedback, it helps us improve the site.

How satisfied are you with this reply?

Thanks for your feedback.

 
 

Question Info


Last updated October 5, 2021 Views 121 Applies to: