Re: Outlook Automation Problem



Norm

Why not use a Distribution List and then send to all members of the
distribution list and then you won't need to loop through all the members
individually. I have used this method before. I have attached a rather crude
sub and ignore some of the code as I have not had a chance to edit it for
this post:

Alastair

Public Sub ShowDistNames()
Dim bolFound As Boolean
Dim objNS As Outlook.NameSpace
Dim objContact As DistListItem
Dim objItems As Outlook.Items
Dim objContactsFolder As Outlook.MAPIFolder
Dim objRecipient As Outlook.Recipient
Dim obj As Object
Dim i As Integer
bolFound = False
Set objNS = objOA.GetNamespace("MAPI")
Set objContactsFolder = objNS.GetDefaultFolder(olFolderContacts)
Set objItems = objContactsFolder.Items
For Each obj In objItems
If obj.Class = olDistributionList Then
Set objContact = obj
If objContact.Subject = "NonAttendanceList" Then
With objContact
For i = 1 To objContact.MemberCount
Set objRecipient = .GetMember(i)
With objRecipient
mvarListBox.AddItem .Name & "; ... " & .Address
End With
Next
bolFound = True
End With
End If
End If
Err.Clear
Next
Set objNS = Nothing
Set obj = Nothing
Set objContact = Nothing
Set objItems = Nothing
Set objContactsFolder = Nothing
If bolFound = False Then
nonAtt.ShowAction ("The distribution list SportNonAttendanceList is
not found. " & vbCrLf & _
"It looks like it has been deleted, renamed or moved.")
Else
nonAtt.ShowAction ("The distribution list SportNonAttendanceList was
found. " & vbCrLf & _
"and opened successfully.")
End If
End Sub

"Norm" <nofo@xxxxxxxxxxx> wrote in message
news:9aQ6f.13699$MN6.807@xxxxxxxxxxxxx
> Veign, Alastair,
>
> Thanks for the answer and I guess my question was not really clear or
> maybe I am doing the emailing wrong to begin with.
>
> The error is not coming when I loop through the contacts and add each one
> to a list called AllUsers. When all the contacts have been added AllUsers
> is used as the Recipient for Outlook email. When the Send command is given
> the error occurs, but the user has no idea which name has not been
> recognized out of the group.
>
> I was just looking for a way to check the names as the program looped
> through them to add them to the AllUsers group and I would trap the error
> here, giving the name to the user, but still letting Outlook send to the
> rest of the group. The way it is now when Outlook generates the error it
> does not send the email to anyone until the bad name is corrected.
>
> If there is not a way of doing this I could have the program send
> individual emails, but I would like to avoid this if possible.
>
> Not having access to a network or exchange server makes it a little
> difficult for me to experiment with different options.
>
> Norm
> "Alastair MacFarlane" <anonymous@xxxxxxxxxxxxx> wrote in message
> news:emBfbm$1FHA.460@xxxxxxxxxxxxxxxxxxxxxxx
>> Norm,
>>
>> I am sorry but I don't have a solution but merely a sense of direction if
>> you don't get a plausible answer. I would look down the Collaboration
>> Data Objects route wich will be able to query the exchange server for
>> information that cannot be obtained directly through the Outlook object
>> model.
>>
>> I am slightly confused as to why a loop through the recipients brings up
>> errors. Could you have different groups set up on the exchange server and
>> you are only looping through a subset of the whole. Our exchange server
>> is grouped by department and you have to select the department to loop
>> through the members.
>>
>> Anyway I would suggest CDO as your most likely way forward.
>>
>> I hope this helps in a small way.
>>
>> Alastair MacFarlane
>>
>> "Norm" <nofo@xxxxxxxxxxx> wrote in message
>> news:mJP6f.13696$MN6.9928@xxxxxxxxxxxxx
>>> Hi,
>>>
>>> I had asked this question in the Outlook group, but did not get an
>>> answer. Hopefully someone here can help me.
>>>
>>> I have an application being used in another state that emails a form to
>>> a
>>> list of people in the users contact list. They are using Outlook and
>>> occasionally get an error message that one or more users is not
>>> recognized
>>> by Outlook.
>>>
>>> The program loops through the list adding each name to the recipient
>>> list
>>> and I was wondering if there was a way to check each name against the
>>> server
>>> at this point to see if it is valid. I do not have access to a network
>>> with
>>> an exchange server to test this on and any help would be appreciated.
>>>
>>> Thanks,
>>> Norm
>>>
>>>
>>>
>>
>>
>
>


.



Relevant Pages

  • Re: Outlook Automation Problem
    ... When I was working at a company that used Outlook and an Exchange server, ... > Dim objNS As Outlook.NameSpace ... > Set objContactsFolder = objNS.GetDefaultFolder ...
    (microsoft.public.vb.general.discussion)
  • Re: Problem when Looping through large number on MS Exchange conta
    ... each message explicitly and resetting it to Nothing inside the loop. ... OutlookSpy - Outlook, CDO ... >>> dim oResults as Outlook.Results ... >>> dim oContact as Outlook.ContactItem ...
    (microsoft.public.office.developer.outlook.vba)
  • Re: Outlook 2003 vba macro
    ... Sue Mosher, Outlook MVP ... > Another way of doing it is to use a for each loop ... 'Move the email Item to the backup folder ... >> Dim objApp As Application ...
    (microsoft.public.outlook.program_vba)
  • Re: looping through inbox messages / debugger under Outlook VBA
    ... Author of Microsoft Outlook 2007 Programming: ... breakpoints, view the content of variables, watch the loops loop, etc. is ... The underlying task is to read through the messages in the inbox and write ... Dim oNameSpace As Outlook.NameSpace ...
    (microsoft.public.office.developer.outlook.vba)
  • Re: Speed of reading email messages
    ... I would first of all release my objects going through the loop, not use so many dot operators assign an overall Items collection and iterate that. ... I would probably use a different API myself when iterating a large collection, for example I use Redemption to avoid the Outlook security and provide access to Stores and properties that aren't exposed in the Outlook object model. ... Dim iSelectedIndex As Integer ... Dim omelette As Object 'Outlook._Mail '= ...
    (microsoft.public.office.developer.outlook.vba)

Loading