read outlook contacts list into Word

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Hi, I posted a question about this in Word programming forum but so far no
response.
I am writing a tool for Word 2002, which includes a userform with a listbox
containing the names of all staff. The names are in everyone's Outlook
Address Book (global) (using Outlook 2002) so it makes sense to get the names
from there.

Here's the code I am using in my Word userform. I admit I am new to this and
do not understand all of the code. It crashes where shown and causes Outlook
to close in the process. I am keen to learn, so any advice will be very
welcome.

Set oNamespc = oApp.GetNamespace("MAPI")
For Each oItm In oNamespc.GetDefaultFolder(olFolderContacts).Items '<--
crashes here
With ListBox1
..AddItem (oItm.FullName)
End With
Next oItm

-
Stephenc
 
I get "Run-time error -2147024809 (80070057). Could not complete the
operation. One or more parameter values are not valid".
----
 
How do you declare the variable "oItm"? Please try it as follows:

Dim obj as object
Dim oContact as Outlook.ContactItem

For each obj in ...
If Typeof obj is Outlook.ContactItem Then
Set oContact=obj
...
Endif
Next
 
Hi Michael,
That fixed it. To do it I also had to add a reference to "Microsoft Outlook
10.0 Object Library" in Word but it now works very well.
Thanks very much for your patience and help, it is much appreciated.

Viele Grüße :-)
Stephenc
----
 
Back
Top