Sub AddOutlookCont()
Dim ol As New Outlook.Application
Dim ci As ContactItem
Dim strAddress As String
Dim strName As String
Dim strFullName As String
Dim strBusiness As String
Dim iSplit As Integer
Dim iResult As Integer
strAddress = Selection.Range
'error check to establish if an address has been
selected
If Len(strAddress) < 1
Then
MsgBox "No address selected!" & vbCr & _
"Select the address and re-run the macro", vbCritical, _
"Select Address"
Exit Sub
End If
'Let the user
see the selected address is correct
iResult = MsgBox("Is the address correct?" & _
vbCr & vbCr & strAddress, vbYesNo, "Address")
If iResult = 7 Then GoTo UserCancelled:
'Prompt for personal contact details, if known
strFullName = InputBox("Enter contact's full name if known" _
& vbCr & "in the format 'Mr. John Smith", "Contact name")
On Error GoTo UserCancelled:
iSplit = InStr(strAddress, Chr(13))
strName = Left(strAddress, iSplit - 1)
strBusiness = Right(strAddress, (Len(strAddress) - Len(strName)))
Set ci = ol.CreateItem(olContactItem)
ci.MailingAddress = strBusiness
ci.CompanyName = strName
If strFullName <> ""
Then ci.FullName = strFullName
ci.FileAs = strName
'Prompt for
category
ci.Categories = InputBox("Category?", "Categories")
ci.Save
Set ol = Nothing
Exit Sub
UserCancelled:
MsgBox "User Cancelled or address not selected"
Set ol = Nothing
End Sub