Outlook Visual Basic - Reminder Event

DavidRGarner
DavidRGarner used Ask the Experts™
on
Using information available via a Google search I have put together an Outlook macro to send an email to a list of recipients when a Calendar reminder fires.  The code below works perfectly as long as I don't try to include any attachments that may be present in the Appointment body/details section.  I want the reminder email that this macro generates to also include attachments if they are present in the appointment item.  Can anyone tell me what code I need to add to make this happen?  I have worked/experimented on this issue for many days with no success.  I have finally decided to ask the experts.  (Note that the source object is an AppointmentItem).   Thanks!

Private Sub Application_Reminder(ByVal EventItem As Object)
Dim MailMsg As MailItem
Set MailMsg = Application.CreateItem(olMailItem)
If EventItem.MessageClass = "IPM.Appointment" Then
  Call SendApptMail(MailMsg, EventItem)
End If
Set MailMsg = Nothing
End Sub
 
Sub SendApptMail(Mail_Item As Object, Appt_Item As Object)
Mail_Item.To = Appt_Item.Location
Mail_Item.Subject = Appt_Item.Subject
Mail_Item.Attachments = Appt_Item.Attachments   'this line throws an error - Help!
Mail_Item.HTMLBody = Appt_Item.Body  'other html formatting omitted for brevity
Mail_Item.Send
End Sub

Open in new window

Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Have you tried to add each attachment individually rather than as a collection?? something like:
for each oAttachment in Appt_Items.Attachments
     Mail_Item.Attachments.add oAttachment
next

Open in new window


Hope this helps

Priz
I tried the .add method and it stops with a run-time error.  I have found that the only way to do this is to save the AppointmentItem attachment to disk and then read it back into the MailItem object.  Very ugly but it works.  I also added a statement to delete the file from disk for cleanup purposes.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial