Insert address and other data from Outlook

M

Mathew

I would like to insert address data and other data from Outlook using a
macro. I have the address info macro down thanks to Graham Mayor's wonderful
examples and explaination at his web site:
http://www.gmayor.com/Macrobutton.htm . However, I need to add a few more
fields, like OrganizationalIDNumber, Department, CustomerID,
GovernmentIDNumber and RadioTelephoneNumber and a few others. I know that
the macros pulls data from the contact in for the address fields effectively.
So, 1st is it possible to insert other type of data from Outlook using the
macro? If so how do I find the field names for the code syntax please see
example below:

Dim OrganizationalIDNumber As String
OrganizationalIDNumber = "<PR_ORGANIZATIONALIDNUMBER>"
OrganizationalIDNumber = Application.GetAddress("", OrganizationalIDNumber,
False, 2, , , True, True)

This returns nothing at all. I’ve tried changing the form of the variable
to:
• OrganizationalIDNumber
• Organizational_ID_Number
• ORGANIZATIONALIDNUMBER
• ORGANIZATIONAL_ID_NUMBER
However, I cannot retrieve the data Organizational ID Number stored in the
Outlook Contact under the Organizational ID Number. Any suggestions?
Thanks for any help!
 
G

Graham Mayor

The available field codes for this function are those listed at the end of
the page. I know of no way of adding to this list. The only way to access
other fields is to use Mail Merge -
http://www.gmayor.com/mailmerge_from_outlook.htm
Another possibility is to map the required field content from unavailable
fields to unused but available fields. There's a macro at the end of
http://www.gmayor.com/merge_labels_with_word_2007.htm which with a little
modification could be used to perform the mapping, but it would be a bit of
a lash-up..

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
D

Doug Robbins - Word MVP

I am not sure how you are determining for what contact you want to insert
the information, but if you were using a userform, you could have a combobox
on that form that you loaded with the contacts and the required fields and
then used the ,boundcolumn property of the combobox to get the fields that
you want for the contact selected in the combobox


Private Sub UserForm_Initialize()
Dim oApp As Outlook.Application
Dim oNspc As NameSpace
Dim oItm As ContactItem
Dim x As Integer
If Not DisplayStatusBar Then
DisplayStatusBar = True
End If
StatusBar = "Please Wait..."
x = 0
Set oApp = CreateObject("Outlook.Application")
Set oNspc = oApp.GetNamespace("MAPI")
For Each oItm In oNspc.GetDefaultFolder _
(olFolderContacts).Items
With Me.cboContactList
.AddItem (oItm.FullName)
.Column(1, x) = oItm.BusinessAddress
.Column(2, x) = oItm.BusinessAddressCity
.Column(3, x) = oItm.BusinessAddressState
.Column(4, x) = oItm.BusinessAddressPostalCode
End With
x = x + 1
MsgBox x
Next oItm
StatusBar = ""
Set oItm = Nothing
Set oNspc = Nothing
Set oApp = Nothing
Dim MyArray() As Variant, i As Integer, j As Integer, m As Integer, n As
Integer, target As Document, newtable As Table, myitem As Range
'Load client data into MyArray
MyArray = cboContactList.List()
' Create a new document containing a table
Application.ScreenUpdating = False
'Sort the data
Set target = Documents.Add
Set newtable = target.Tables.Add(Range:=target.Range(0, 0),
numrows:=cboContactList.ListCount, NumColumns:=5)
' Populate the cells of the table with the contents of the array
For i = 1 To cboContactList.ListCount
For j = 1 To 5
newtable.Cell(i, j).Range.InsertBefore MyArray(i - 1, j - 1)
Next j
Next i
' sort the table
newtable.Sort ExcludeHeader:=False ', FieldNumber:="Column 1",
SortFieldType:=wdSortFieldText, SortOrder:=wdSortOrderAscending
i = newtable.Rows.Count
' Get the number of columns in the table of client details
j = 5
' Set the number of columns in the Listbox to match
' the number of columns in the table of client details
cboContactList.ColumnCount = 5
' Define an array to be loaded with the client data
Dim NewArray() As Variant
'Load client data into MyArray
ReDim NewArray(i, j)
For n = 0 To j - 1
For m = 0 To i - 1
Set myitem = newtable.Cell(m + 1, n + 1).Range
myitem.End = myitem.End - 1
NewArray(m, n) = myitem.Text
Next m
Next n
' Load data into combobox
cboContactList.List() = NewArray
target.Close wdDoNotSaveChanges
Application.ScreenUpdating = True

End Sub

In the application in which I was using this, I was then displaying the
information for the selected contact in controls on the userform by means of
the following code:

Private Sub cboContactList_Change()
txtAddress1 = cboContactList.Column(0)
txtAddress2 = cboContactList.Column(1)
txtAddress3 = cboContactList.Column(2)
txtAddress4 = cboContactList.Column(3)
txtAddress5 = cboContactList.Column(4)
End Sub

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP
 
G

Graham Mayor

The method under discussion calls the AddressBook dialog which is limited in
the fields that it can access; this method isn't and so it should be
possible to adapt it to produce the required results. Thanks for reminding
me of it :)

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


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
M

Mathew

Doug, Graham: I actually used Graham advice and got the project to work.
But, I'm going to spend some time re-thinking it using Doug's approach.
Thank you both!
 
G

Graham Mayor

I have been playing with Doug's suggested method - see also
http://msdn2.microsoft.com/en-us/library/aa260784.aspx and while it does
offer far greater flexibility, the communication with Outlook is much slower
than with the more limited Addressbook function. I guess you have to trade
convenience for practicality if you want more than Addressbook can provide.

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


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

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