Creating Outlook contacts in Word

R

Roderick O'Regan

I have created a template in Word which works in all versions starting
from 2000.

There is a userform with a combobox which retrieves the company names
of people located in my Contacts folder in Outlook. This allows the
user to select a company which then puts the full address on paper
when the OK button is clicked.

All of this works OK.

However, what I would like to do is create another user form in Word
to allow operators to create a new Contact and then send it to the
default Outlook Contacts folder. All this without having to go into
Outlook, etc, etc.

I've managed to get some great help from the various sources on the
internet on how to GET names from Outlook using all the appropriate
field names and so on.

What I cannot puzzle out is how to PUT them into Outlook from Word
using VBA.

I'm sure I've seen this procedure set out somewhere recently whilst
trawling through the various newsgroups but it's a bit like a taxi in
wet weather: when you want one they can never be found!

Can anyone nudge me in the right direction, please?

Regards

Roderick O'Regan
 
S

Steve Yandl

Roderick,

Here is a small routine I created in an Excel userform that does roughly
what you want. You will be pulling the values from Word rather than an
Excel worksheet but I think this will show you enough to set up your sub.
My subroutine is supposed to create a whole set of new contacts, not just
one.

Note that olApp was declared as a public variable and set as New
Outlook.Application outside this subroutine.

Private Sub CommandButton3_Click()

Dim itemContact As Outlook.ContactItem
Dim S As Integer
Dim rngA As Excel.Range

Set rngA = Sheets("Sheet1").UsedRange

For S = 1 To rngA.Rows.Count
If Sheets("Sheet1").Cells(S, 3).Value = "NO" Then
Set itemContact = olApp.CreateItem(olContactItem)
With itemContact
.FullName = Sheets("Sheet1").Cells(S, 1).Value
.Email1Address = Sheets("Sheet1").Cells(S, 2).Value
.Save
End With
End If
Next


End Sub

Steve
 
R

Roderick O'Regan

Thanks Steve for your helpful nudge.

Will get my head around this and let you know of the outcome.

Regards

Roderick
 
D

Doug Robbins - Word MVP

Note that to use Outlook objects as done in Steve's code, you will need to
set a reference to the Microsoft Outlook [version number] Object Library
under Tools>References in the Visual Basic Editor.

--
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
 
R

Roderick O'Regan

Thanks Doug for the timely advice. I'd forgotten about that.

However, when I checked just now it was already set to Outlook 10.0
Object Library so I must have done it at some time.

Roderick
 

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