Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / Word / Programming / March 2008

Tip: Looking for answers? Try searching our database.

Insert address and other data from Outlook

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Mathew - 11 Mar 2008 14:58 GMT
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!
Graham Mayor - 11 Mar 2008 15:51 GMT
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..

Signature

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> 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
[quoted text clipped - 22 lines]
> suggestions?
> Thanks for any help!
Mathew - 11 Mar 2008 18:37 GMT
Graham:  Bummmer, I was afraid of that!  Thank you very much for your help!!

> 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
[quoted text clipped - 32 lines]
> > suggestions?
> > Thanks for any help!
Doug Robbins - Word MVP - 12 Mar 2008 04:09 GMT
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

Signature

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

> Graham:  Bummmer, I was afraid of that!  Thank you very much for your
> help!!
[quoted text clipped - 37 lines]
>> > suggestions?
>> > Thanks for any help!
Graham Mayor - 12 Mar 2008 08:24 GMT
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 :)

Signature

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> 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
[quoted text clipped - 135 lines]
>>>> suggestions?
>>>> Thanks for any help!
Mathew - 12 Mar 2008 15:11 GMT
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!  

> 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
[quoted text clipped - 126 lines]
> >> > suggestions?
> >> > Thanks for any help!
Graham Mayor - 13 Mar 2008 07:44 GMT
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.

Signature

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

My web site www.gmayor.com
Word MVP web site http://word.mvps.org
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>

> 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
[quoted text clipped - 149 lines]
>>>>> Any suggestions?
>>>>> Thanks for any help!

Rate this thread:






 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.