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

Excel 2002. How would I programmatically access a distribution list in
Outlook from Excel. I need to run through the distribution list (called
"Chaplains"), examining their "company" and "email" fields, and send an email
message to selected folks in the distribution list.

Another question. When I programmatically send mutiple Outlook emails from
Excel (which I already know how to do), how do I keep Outlook from prompting
me every time an email is sent? It prompts me that someone outside of
Outlook is trying to send a email. I already know this! How can I shut this
off and turn it back on? Thanks.

  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default Accessing Outlook from Excel

on the second part, take a look at http://www.rondebruin.nl/mail/prevent.htm

--
HTH

-------

Bob Phillips
"Chaplain Doug" wrote in message
...
Excel 2002. How would I programmatically access a distribution list in
Outlook from Excel. I need to run through the distribution list (called
"Chaplains"), examining their "company" and "email" fields, and send an

email
message to selected folks in the distribution list.

Another question. When I programmatically send mutiple Outlook emails

from
Excel (which I already know how to do), how do I keep Outlook from

prompting
me every time an email is sent? It prompts me that someone outside of
Outlook is trying to send a email. I already know this! How can I shut

this
off and turn it back on? Thanks.



  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default Accessing Outlook from Excel

Chaplain Doug,

The following subroutine will iterate through your contacts list, identify
items that are distrubution lists rather than contacts, identify one named
"Chaplains" and then iterate through the members of the chaplains list. For
each member, it confirms that the address can be resolved and then it
searches the contacts folder for a match to the email address (only looking
at the primary email addy if there are several for a contact). It populates
sheet 1 with what it finds placing Full Name in column A, Email address in
Column B and Company Name in column C.

This does cause the annoying warning box to pop up. When I tested, I just
selected the option to allow access for one minute and then clicked yes.
For the small groups I tested it on the one minute was more than enough
time. This should be easy enough to marry up with your screening criteria
and mailing subroutine.

______________________________

Sub ListMembers()

Dim olApp As New Outlook.Application

Dim olNS As Outlook.Namespace

Dim ctFolder As Outlook.MAPIFolder

Dim myDistList As Outlook.DistListItem

Dim ctFolderItems As Outlook.Items

Dim myRcpnt As Outlook.Recipient

Dim iterateCtItems As Integer

Dim iterateMembers As Integer

Dim countCtItems As Integer

Dim countMembers As Integer

Dim R As Integer

Dim criteria As String

Dim itm As Object



Set olNS = olApp.GetNamespace("MAPI")

Set ctFolder = olNS.GetDefaultFolder(olFolderContacts)

Set ctFolderItems = ctFolder.Items

Sheets("Sheet1").UsedRange.Clear



countCtItems = ctFolderItems.Count

R = 1



For iterateCtItems = 1 To countCtItems

If TypeName(ctFolderItems.Item(iterateCtItems)) = "DistListItem" Then

Set myDistList = ctFolderItems.Item(iterateCtItems)

If myDistList.DLName = "Chaplains" Then

countMembers = myDistList.MemberCount

For iterateMembers = 1 To countMembers

Set myRcpnt =
olApp.Session.CreateRecipient(myDistList.GetMember (iterateMembers).Address)

myRcpnt.Resolve

If myRcpnt.Resolved = True Then

criteria = "[Email1Address] = " & myRcpnt.Address

Set itm = ctFolderItems.Find(criteria)

Sheets("Sheet1").Cells(R, 1).Value = itm.FullName

Sheets("Sheet1").Cells(R, 2).Value = itm.Email1Address

Sheets("Sheet1").Cells(R, 3).Value = itm.CompanyName

R = R + 1

End If

Next iterateMembers

End If

End If



Next iterateCtItems



Set olNS = Nothing

Set olApp = Nothing

End Sub



-------------------------------------------------



Steve Yandl

"Chaplain Doug" wrote in message
...
Excel 2002. How would I programmatically access a distribution list in
Outlook from Excel. I need to run through the distribution list (called
"Chaplains"), examining their "company" and "email" fields, and send an
email
message to selected folks in the distribution list.

Another question. When I programmatically send mutiple Outlook emails
from
Excel (which I already know how to do), how do I keep Outlook from
prompting
me every time an email is sent? It prompts me that someone outside of
Outlook is trying to send a email. I already know this! How can I shut
this
off and turn it back on? Thanks.



  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 127
Default Accessing Outlook from Excel

Thanks Steve. Finally a solution!

"Steve Yandl" wrote:

Chaplain Doug,

The following subroutine will iterate through your contacts list, identify
items that are distrubution lists rather than contacts, identify one named
"Chaplains" and then iterate through the members of the chaplains list. For
each member, it confirms that the address can be resolved and then it
searches the contacts folder for a match to the email address (only looking
at the primary email addy if there are several for a contact). It populates
sheet 1 with what it finds placing Full Name in column A, Email address in
Column B and Company Name in column C.

This does cause the annoying warning box to pop up. When I tested, I just
selected the option to allow access for one minute and then clicked yes.
For the small groups I tested it on the one minute was more than enough
time. This should be easy enough to marry up with your screening criteria
and mailing subroutine.

______________________________

Sub ListMembers()

Dim olApp As New Outlook.Application

Dim olNS As Outlook.Namespace

Dim ctFolder As Outlook.MAPIFolder

Dim myDistList As Outlook.DistListItem

Dim ctFolderItems As Outlook.Items

Dim myRcpnt As Outlook.Recipient

Dim iterateCtItems As Integer

Dim iterateMembers As Integer

Dim countCtItems As Integer

Dim countMembers As Integer

Dim R As Integer

Dim criteria As String

Dim itm As Object



Set olNS = olApp.GetNamespace("MAPI")

Set ctFolder = olNS.GetDefaultFolder(olFolderContacts)

Set ctFolderItems = ctFolder.Items

Sheets("Sheet1").UsedRange.Clear



countCtItems = ctFolderItems.Count

R = 1



For iterateCtItems = 1 To countCtItems

If TypeName(ctFolderItems.Item(iterateCtItems)) = "DistListItem" Then

Set myDistList = ctFolderItems.Item(iterateCtItems)

If myDistList.DLName = "Chaplains" Then

countMembers = myDistList.MemberCount

For iterateMembers = 1 To countMembers

Set myRcpnt =
olApp.Session.CreateRecipient(myDistList.GetMember (iterateMembers).Address)

myRcpnt.Resolve

If myRcpnt.Resolved = True Then

criteria = "[Email1Address] = " & myRcpnt.Address

Set itm = ctFolderItems.Find(criteria)

Sheets("Sheet1").Cells(R, 1).Value = itm.FullName

Sheets("Sheet1").Cells(R, 2).Value = itm.Email1Address

Sheets("Sheet1").Cells(R, 3).Value = itm.CompanyName

R = R + 1

End If

Next iterateMembers

End If

End If



Next iterateCtItems



Set olNS = Nothing

Set olApp = Nothing

End Sub



-------------------------------------------------



Steve Yandl

"Chaplain Doug" wrote in message
...
Excel 2002. How would I programmatically access a distribution list in
Outlook from Excel. I need to run through the distribution list (called
"Chaplains"), examining their "company" and "email" fields, and send an
email
message to selected folks in the distribution list.

Another question. When I programmatically send mutiple Outlook emails
from
Excel (which I already know how to do), how do I keep Outlook from
prompting
me every time an email is sent? It prompts me that someone outside of
Outlook is trying to send a email. I already know this! How can I shut
this
off and turn it back on? Thanks.




  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 127
Default Got an Error When Trying Your Code

Dear Steve:

Last night when I tried this code in Access 2002, it worked fine. Today
When I try it on Access 2003 I get an error on the following line:

Set itm = ctFolderItems.Find(criteria)

When it tries to do the "set" I get:

Runtime error -313393143 (ed520009)
Automation Error

Do you have any idea what might case this?



  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 127
Default Got an Error When Trying Your Code

Dear Steve:

Just needed to add quotes to criteria.

criteria = "[Email1Address] = '" & myRcpnt.Address & "'"
Set itm = ctFolderItems.Find(criteria)

"Chaplain Doug" wrote:

Dear Steve:

Last night when I tried this code in Access 2002, it worked fine. Today
When I try it on Access 2003 I get an error on the following line:

Set itm = ctFolderItems.Find(criteria)

When it tries to do the "set" I get:

Runtime error -313393143 (ed520009)
Automation Error

Do you have any idea what might case this?

  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 117
Default Got an Error When Trying Your Code

Odd that there would be a version specific issue with the quotes but I've
seen a lot stranger things. Glad you got it figured out.

Steve


"Chaplain Doug" wrote in message
...
Dear Steve:

Just needed to add quotes to criteria.

criteria = "[Email1Address] = '" & myRcpnt.Address & "'"
Set itm = ctFolderItems.Find(criteria)



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
accessing outlook data using excel macro jaundice Charts and Charting in Excel 0 June 27th 07 11:30 PM
excel open in outlook if outlook is running kirk Excel Discussion (Misc queries) 0 May 24th 06 06:42 PM
Accessing Outlook from Excel Chaplain Doug Excel Discussion (Misc queries) 0 December 19th 04 11:39 PM
Late Binding to Outlook from Excel: Outlook modifies email body Lenny Wintfeld Excel Programming 0 December 12th 04 04:03 PM
Accessing Word from Excel pikus Excel Programming 4 January 14th 04 07:41 PM


All times are GMT +1. The time now is 01:32 AM.

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"