Fields and Macros

J

Joseph McGuire

I got a lot of help last month (special thanks to G. Mayor) setting up
Macrobuttons with a Macro to pull certain information, including a Contact's
phone number, from OL and insert it in my Word document. Double-clicking on
the button gets me the Contact's name and his/her phone number and puts it
in a Word document that I use as a log to account for phone charges. This
has worked quite well until I hit a glitch. The macro is set to retrieve
OFFICE_TELEPHONE_NUMBER. Most of my contacts have a Business phone, as the
field seems to be called in OL, which I use for their direct line. This
appears to be what the macro is retrieving. For others I have their phone
number as Company Phone since I don't know or they do not have a direct
line. For such Contacts, my macro returns the Contact's name but a blank
for the number. Then I have to cut and paste the number into my log, which
is why I wanted the Macro/Macrobutton in the first place. Is there any
reasonable way short of a vba nightmare to either set some priorities (e.g.,
if there is no Business Number, look for Company Number?

Let's not even get into Contacts who also have mobile numbers, etc. The
combination of Business Phone and Company phone probably cover 95% of my
billable calls. I will be happy if this macro works for that 95% but I am
not going to kill myself to get from 95 to 100%!
 
G

Graham Mayor

The function that enables Outlook data to be inserted by the macro will not
access all the fields in Outlook contacts. The fields that may be accessed
are listed at the end of the web page http://www.gmayor.com/Macrobutton.htm
If the field that contains the data you wish to use is contained in one of
those fields then it should be possible to conditionally choose
between them in the macro code.

The problem area that I have not been able to resolve is the need to access
Outlook before you can determine what the record contains and then decide
what to do with it (better minds than mine frequent the vba newsgroups is
you wish to bounce the problem there to overcome the double access).

Public Sub InsertAddressAndPhoneFromOutlook()
Dim strCode, strAddress, strName, strPhone As String

strName = "<PR_DISPLAY_NAME>"
strPhone = "<PR_OFFICE_TELEPHONE_NUMBER>"

strCode = strName & vbTab & strPhone
'Let the user choose the name in Outlook
strAddress = Application.GetAddress("", strCode, _
False, 1, , , True, True)

If Right(strAddress, 1) = Chr(9) Then
MsgBox "No office number available" & vbCr _
& "select again for alternative number"

'Define alternative number
strPhone = "<PR_OFFICE2_TELEPHONE_NUMBER>"
strCode = strName & vbTab & strPhone
strAddress = Application.GetAddress("", strCode, _
False, 1, , , True, True)
End If

'Insert the name at the current insertion point
If ActiveDocument.ProtectionType <> wdNoProtection Then
bProtected = True
ActiveDocument.Unprotect
ActiveDocument.FormFields("NameOfFormfield").Result = _
strAddress
Else
Selection.TypeText strAddress
End If
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP

My web site www.gmayor.com

<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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