Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 586
Default Call Outlook Contacts from Excel Userform

Is it possible to get information from the Users Outlook contacts in my Excel
Userform. For example, when the Userform is initialized in Excel it will
have list of all the Company Names in the Users Outlook Contacts. When the
user selects a company, things like the address, phone number will
automatically be filled in the Userform. Is this possible?

Anything to get me going would help?
--
Cheers,
Ryan
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 789
Default Call Outlook Contacts from Excel Userform

Hi
The declarations section here and the first two subs can be used to
connect & disconnect with Outlook from Excel which you will be able to
use as is.
The last sub I use to create a Contacts folder from information in
excel (i.e. Excel TO Outlook). It takes information from four columns
starting from A1 (and assumes first row is headers). You should be
able to reverse the write bit
i.e. With objStudent
.LastName = MailInfo(i + 1, 1)
.FirstName = MailInfo(i + 1, 2)
.Email1Address = MailInfo(i + 1, 3)
.BusinessAddress = MailInfo(i + 1, 4)
.Save
End With

to go from Outlook to Excel by reading the info from objFolder =
objNamespace.GetDefaultFolder(olFolderContacts)

regards
Paul

***CODE****
Option Explicit
Option Base 1
Public objOutlook As Outlook.Application
Public objNamespace As Outlook.Namespace
Public OutlookWasRunning As Boolean

'Interface with Outlook objects required will be through this sub.
'It is called by any sub requiring access to Outlook.
Public Sub DeclareOutlookObjects()
Application.ScreenUpdating = False
On Error Resume Next
Err.Clear
Set objOutlook = GetObject(, "Outlook.Application") 'If
Outlook is already open, flag it with Boolean
If Err.Number < 0 Then OutlookWasRunning = False Else
OutlookWasRunning = True
On Error GoTo 0
Err.Clear 'keep err tidy
If Not OutlookWasRunning Then
Set objOutlook = CreateObject("Outlook.Application") 'fresh
version of Outlook
End If
Set objNamespace = objOutlook.GetNamespace("MAPI")
objNamespace.Logon
End Sub

'Releases Public variable objects after Outlook session
Public Sub ReleaseOutlookObjects()
Application.ScreenUpdating = False
objNamespace.Logoff
Set objNamespace = Nothing
If Not OutlookWasRunning Then objOutlook.Quit
Set objOutlook = Nothing
End Sub

Public Sub MakeContactsFolders()
Dim EmailFolderName As String
Dim objFolder As MAPIFolder, objNewFolder As MAPIFolder, objStudent As
Outlook.ContactItem
Dim Delegates As Long, i As Long
Dim MailInfo As Variant
Application.ScreenUpdating = False
EmailFolderName = InputBox("What is the email folder name?", "Make
an Outlook Contacts Folder")
If EmailFolderName = "" Then Exit Sub
DeclareOutlookObjects

'DeclareOutlookObjects() already run to Connect up to Outlook and
creates objNameSpace
'create a new contacts folder in the Contacts Folders, if that
exists
'need to delete it first if it already exists

Set objFolder = objNamespace.GetDefaultFolder(olFolderContacts)
On Error Resume Next 'see if "My Contacts" exists
Set objNewFolder = objFolder.Folders(EmailFolderName)
On Error GoTo 0
'If folder already exists, it is last years so delete it
If Not objNewFolder Is Nothing Then objNewFolder.Delete
Set objNewFolder = objFolder.Folders.Add(EmailFolderName,
olFolderContacts)
'get the contact info
MailInfo = ActiveSheet.Range("A1").CurrentRegion.Value
Delegates = UBound(MailInfo, 1) - 1 'not header
'Add the contact info to the created folder

For i = 1 To Delegates 'all attendees
Set objStudent = objNewFolder.Items.Add(olContactItem)
With objStudent
.LastName = MailInfo(i + 1, 1)
.FirstName = MailInfo(i + 1, 2)
.Email1Address = MailInfo(i + 1, 3)
.BusinessAddress = MailInfo(i + 1, 4)
.Save
End With
Next i
objNewFolder.ShowAsOutlookAB = True 'see it in address book
If objNewFolder.Items.Count = 0 Then objNewFolder.Delete
'not required if empty

MsgBox "Your email folder is a subfolder of your Contacts Folder",
vbOKOnly
Set objStudent = Nothing
Set objNewFolder = Nothing 'GroupContacts
Set objFolder = Nothing 'contacts folder
ReleaseOutlookObjects 'disconnect from Outlook
End Sub
On Jun 26, 8:02*am, RyanH wrote:
Is it possible to get information from the Users Outlook contacts in my Excel
Userform. *For example, when the Userform is initialized in Excel it will
have list of all the Company Names in the Users Outlook Contacts. *When the
user selects a company, things like the address, phone number will
automatically be filled in the Userform. *Is this possible?

Anything to get me going would help?
--
Cheers,
Ryan


Reply
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Contacts from Excel to Outlook Ergg Excel Discussion (Misc queries) 1 January 20th 10 10:12 PM
How do I export contacts from Excel back to Outlook Contacts? corvettego Excel Discussion (Misc queries) 2 August 17th 09 06:29 PM
Build a userform on excel to copy contacts from outlook 2003 Oggy Excel Programming 1 January 2nd 07 05:48 PM
Invoke Outlook Contacts From Within Excel Cole Excel Programming 1 October 26th 06 08:42 PM
Outlook and Excel Integration for Contacts Shauna Koppang Excel Programming 14 August 22nd 03 11:32 PM


All times are GMT +1. The time now is 08:41 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"