PC Review


Reply
Thread Tools Rate Thread

Can I open an Outlook dialog box from Excel?

 
 
LuisE
Guest
Posts: n/a
 
      22nd Dec 2007
I would like to insert an email address from the outlook insert names dialog
box into the active cell. Is it possible?

I can't find any reference to the Outlook built-in dialog boxes.

Thanks in advance
 
Reply With Quote
 
 
 
 
Steve Yandl
Guest
Posts: n/a
 
      23rd Dec 2007
The lingo used in Outlook is somewhat different than what you find in Excel
and Word which is why you don't find info on built in dialog boxes for
Outlook. You probably want a form associated with an "Inspector".

You could do something like

________________________
Set myOL = CreateObject("Outlook.Application")
Set myItem = myOL.Application.CreateItem(0)
Set myInspect = myItem.GetInspector
myInspect.Activate
-----------------------------------------------
but that just gets you the form for creating a new message. You could use
SendKeys to send a period and get the 'Select Names' window but I don't have
any idea how you would capture the name when the user selected one.

I'd suggest something like I've got below. For the example, I created a
UserForm1 that contains the list box, ListBox1. I also created a subroutine
in a module that simply has the one line:
UserForm1.Show

When the user form is activated, it grabs all the contacts in your contacts
folder and populates ListBox1 with those names. When ListBox1 changes
because the user selects one of the listed names, the associated email
address is entered in Cell C2. The one annoying (but necessary) feature is
that the user will have to click an OK to a security warning that some
program is harvesting email address info and they need to give approval for
a certain number of minutes or kill the routine.

You might also want to capture last name to the array and alphabetize the
list before populating the listbox but I wanted to keep it simple for now.

__________________________

Private arrContacts() As String

Private Sub ListBox1_Change()
Cells(2, 3).Value = arrContacts(1, ListBox1.ListIndex)
End Sub

Private Sub UserForm_Activate()

Const olFolderContacts = 10

Dim intCount As Integer

ReDim arrContacts(1, 0)
arrContacts(0, 0) = ""
arrContacts(1, 0) = ""
intCount = 1

Set objOL = CreateObject("Outlook.Application")
Set objNS = objOL.GetNamespace("MAPI")
Set objFldContacts = objNS.GetDefaultFolder(olFolderContacts)

For Each myItem In objFldContacts.Items
If TypeName(myItem) = "ContactItem" Then
ReDim Preserve arrContacts(1, intCount)
arrContacts(0, intCount) = myItem.FullName
arrContacts(1, intCount) = myItem.Email1Address
intCount = intCount + 1
End If
Next myItem

For L = 0 To UBound(arrContacts, 2)
ListBox1.AddItem arrContacts(0, L), L
Next L

Set objFldContacts = Nothing
Set objNS = Nothing
Set objOL = Nothing
End Sub


___________________________

Steve Yandl


"LuisE" <(E-Mail Removed)> wrote in message
news:9D7BFD9D-2C92-402A-94FA-(E-Mail Removed)...
>I would like to insert an email address from the outlook insert names
>dialog
> box into the active cell. Is it possible?
>
> I can't find any reference to the Outlook built-in dialog boxes.
>
> Thanks in advance



 
Reply With Quote
 
LuisE
Guest
Posts: n/a
 
      23rd Dec 2007
Thanks a lot Steve for the prompt response and for your time.
I found your approach very helpful.

I think the listbox is a multiselect one. I'm looking to transfer all the
selected entries into the same cell, separated by ";"

Would change FolderContacts for AddressLists allow me to capture all
addresses?

Thanks a lot again

"Steve Yandl" wrote:

> The lingo used in Outlook is somewhat different than what you find in Excel
> and Word which is why you don't find info on built in dialog boxes for
> Outlook. You probably want a form associated with an "Inspector".
>
> You could do something like
>
> ________________________
> Set myOL = CreateObject("Outlook.Application")
> Set myItem = myOL.Application.CreateItem(0)
> Set myInspect = myItem.GetInspector
> myInspect.Activate
> -----------------------------------------------
> but that just gets you the form for creating a new message. You could use
> SendKeys to send a period and get the 'Select Names' window but I don't have
> any idea how you would capture the name when the user selected one.
>
> I'd suggest something like I've got below. For the example, I created a
> UserForm1 that contains the list box, ListBox1. I also created a subroutine
> in a module that simply has the one line:
> UserForm1.Show
>
> When the user form is activated, it grabs all the contacts in your contacts
> folder and populates ListBox1 with those names. When ListBox1 changes
> because the user selects one of the listed names, the associated email
> address is entered in Cell C2. The one annoying (but necessary) feature is
> that the user will have to click an OK to a security warning that some
> program is harvesting email address info and they need to give approval for
> a certain number of minutes or kill the routine.
>
> You might also want to capture last name to the array and alphabetize the
> list before populating the listbox but I wanted to keep it simple for now.
>
> __________________________
>
> Private arrContacts() As String
>
> Private Sub ListBox1_Change()
> Cells(2, 3).Value = arrContacts(1, ListBox1.ListIndex)
> End Sub
>
> Private Sub UserForm_Activate()
>
> Const olFolderContacts = 10
>
> Dim intCount As Integer
>
> ReDim arrContacts(1, 0)
> arrContacts(0, 0) = ""
> arrContacts(1, 0) = ""
> intCount = 1
>
> Set objOL = CreateObject("Outlook.Application")
> Set objNS = objOL.GetNamespace("MAPI")
> Set objFldContacts = objNS.GetDefaultFolder(olFolderContacts)
>
> For Each myItem In objFldContacts.Items
> If TypeName(myItem) = "ContactItem" Then
> ReDim Preserve arrContacts(1, intCount)
> arrContacts(0, intCount) = myItem.FullName
> arrContacts(1, intCount) = myItem.Email1Address
> intCount = intCount + 1
> End If
> Next myItem
>
> For L = 0 To UBound(arrContacts, 2)
> ListBox1.AddItem arrContacts(0, L), L
> Next L
>
> Set objFldContacts = Nothing
> Set objNS = Nothing
> Set objOL = Nothing
> End Sub
>
>
> ___________________________
>
> Steve Yandl
>
>
> "LuisE" <(E-Mail Removed)> wrote in message
> news:9D7BFD9D-2C92-402A-94FA-(E-Mail Removed)...
> >I would like to insert an email address from the outlook insert names
> >dialog
> > box into the active cell. Is it possible?
> >
> > I can't find any reference to the Outlook built-in dialog boxes.
> >
> > Thanks in advance

>
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
Getting the dialog open blurb, but Outlook won't let me open it =?Utf-8?B?TWFyeQ==?= Microsoft Access 1 6th Jan 2007 03:56 AM
excel and VB Open Dialog box =?Utf-8?B?QW5ha2luIE1vb253YWxrZXI=?= Microsoft Excel Misc 2 13th Sep 2005 08:38 AM
how to add a dialog box when you first open excel workbook =?Utf-8?B?RXJpbg==?= Microsoft Access Macros 1 22nd Jun 2005 04:22 PM
Open Dialog Excel 97 not appear =?Utf-8?B?d2FuY2U=?= Microsoft Excel Misc 1 22nd May 2004 03:39 AM
How to get a OPEN/SAVE dialog option window when open Excel from IE browser Eddie Wang Microsoft Excel Misc 0 3rd Oct 2003 07:01 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 06:07 PM.