leenabhanot
Programmer
Hi I am using Ms Outlook to go through a distro list and send an email to everyone on the list.
For each person, on the distro list, I create a custom report using access and send that as an attachement using a different naming convention for each person.
My problem is that after I have sent the mail to 1 person, I get an error saying that "the object being referenced to has been moved or deleted" I am not really sure how to by pass it.
I am using the following code.
I would appreciate any help. Thanks a lot.
Dim objOL As Object
Dim myItem As Items
Dim a(10) As String
Dim myOLItem As Outlook.MailItem
Dim filename As String
dim fileAttach As Outlook.Attachments
Set objOL = CreateObject("Outlook.Application"
Set myNameSpace = objOL.GetNamespace("MAPI"
Set myFolder = myNameSpace.GetDefaultFolder(olFolderInbox)
Set myList = myNameSpace.GetDefaultFolder(olFolderContacts)
Set myOLItem = Application.CreateItem(olMailItem)
Set myAttachments = myOLItem.Attachments
Set myDistList = myList.Items.Item("Project Team"
For y = 1 To myDistList.MemberCount
a = myDistList.GetMember.Name
myAttachments.Add "C:\" & a & ".xls"
With myOLItem
.To = a
.Subject = "Sample item"
.Body = "This is a sample message."
End With
myOLItem.Send
Next y
Set objOL = Nothing
MsgBox "Done"
For each person, on the distro list, I create a custom report using access and send that as an attachement using a different naming convention for each person.
My problem is that after I have sent the mail to 1 person, I get an error saying that "the object being referenced to has been moved or deleted" I am not really sure how to by pass it.
I am using the following code.
I would appreciate any help. Thanks a lot.
Dim objOL As Object
Dim myItem As Items
Dim a(10) As String
Dim myOLItem As Outlook.MailItem
Dim filename As String
dim fileAttach As Outlook.Attachments
Set objOL = CreateObject("Outlook.Application"
Set myNameSpace = objOL.GetNamespace("MAPI"
Set myFolder = myNameSpace.GetDefaultFolder(olFolderInbox)
Set myList = myNameSpace.GetDefaultFolder(olFolderContacts)
Set myOLItem = Application.CreateItem(olMailItem)
Set myAttachments = myOLItem.Attachments
Set myDistList = myList.Items.Item("Project Team"
For y = 1 To myDistList.MemberCount
a = myDistList.GetMember.Name
myAttachments.Add "C:\" & a & ".xls"
With myOLItem
.To = a
.Subject = "Sample item"
.Body = "This is a sample message."
End With
myOLItem.Send
Next y
Set objOL = Nothing
MsgBox "Done"