Прикрепление сообщения электронной почты к встрече

Я могу успешно использовать приведенный ниже код, чтобы добавить электронное письмо к встрече, прежде чем сохранять ее в своем календаре. Однако, когда я пытаюсь заполнить электронное письмо до того, как оно попадет на встречу, оно будет пустым, как только встреча будет сохранена в Outlook.

Есть ли способ сохранить электронное письмо во время встречи со всей соответствующей информацией, которую я передаю ему в With olMail? Если да, то как мне этого добиться?

Private Sub calendarUpdate()

'puts an appointment and agenda into my outlook calendar
Dim olApp As Outlook.Application
Dim olApt As AppointmentItem
Dim olMail As MailItem




Set olApp = New Outlook.Application
Set olApt = olApp.CreateItem(olAppointmentItem)
Set olMail = olApp.CreateItem(olMailItem)



emailText = "<H3>Hi Engineer,<br></H3>" & _
            "Can you please fill in the agenda template below (marked red)  and send it back to me ASAP, I will reformat the email where necessary before sending it to the broker/client<br><br>." & _
            "Cheers"

With olMail
    .To = ActiveCell.Offset(0, 21)
    .Subject = ActiveCell.Offset(0, 2) & " " & ActiveCell.Offset(0, 3) & " Agenda Letter Review."
    .HTMLBody = emailText
End With


With olApt
    .AllDayEvent = True
    .Start = Label3.Caption
    .End = Label3.Caption
    .Subject = ActiveCell.Offset(0, 18)
    .Location = ActiveCell.Offset(0, 4) & ", " & ActiveCell.Offset(0, 5) & ", " & ActiveCell.Offset(0, 6) & ", " & ActiveCell.Offset(0, 7) & " " & ActiveCell.Offset(0, 8)
    .Attachment.Add olMail
    .Categories = "EA to Schedule"
    .ReminderSet = True
    .Save
End With


End Sub

person Michael    schedule 12.09.2015    source источник
comment
Я понял это, я не понимаю, почему это работает, а вышеперечисленное нет, но это не имеет большого значения.   -  person Michael    schedule 13.09.2015


Ответы (2)


Сначала сохраните сообщение:

olMail.Save
.Attachment.Add olMail
olMail.Delete
person Dmitry Streblechenko    schedule 13.09.2015

Я добавил Dim myCopiedMessage As Outlook.MailItem, затем установил для этого элемента следующее

Set myCopiedMessage = olMail.Copy

Затем добавил это как вложение. Я понятия не имею, почему это сработало, а мой другой код — нет, но это не относится к делу.

Private Sub calendarUpdate()

'puts a possible appointment into my outlook calendar
Dim olApp As Outlook.Application
Dim olApt As Outlook.AppointmentItem
Dim olMail As Outlook.MailItem
Dim myCopiedMessage As Outlook.MailItem



Set olApp = New Outlook.Application
Set olApt = olApp.CreateItem(olAppointmentItem)
Set olMail = olApp.CreateItem(olMailItem)



emailText = "<H3>Hi Engineer,<br></H3>" & _
                "Can you please fill in the agenda template below (marked red) and send it back to me ASAP, I will reformat the email where necessary before sending it to the broker/client<br><br>." & _
                "Cheers"

With olMail
    .To = ActiveCell.Offset(0, 21)
    .Subject = ActiveCell.Offset(0, 2) & " " & ActiveCell.Offset(0, 3) & " Agenda Letter Review."
    .HTMLBody = emailText
End With

Set myCopiedMessage = olMail.Copy

With olApt
    .AllDayEvent = True
    .Start = Label3.Caption
    .End = Label3.Caption
    .Subject = ActiveCell.Offset(0, 18)
    .Location = ActiveCell.Offset(0, 4) & ", " & ActiveCell.Offset(0, 5) & ", " & ActiveCell.Offset(0, 6) & ", " & ActiveCell.Offset(0, 7) & " " & ActiveCell.Offset(0, 8)
    .attachMents.Add myCopiedMessage, 1
    .Categories = "EA to Schedule"
    .ReminderSet = True
    .Save
End With


End Sub
person Michael    schedule 12.09.2015
comment
Если бы это был ответ, не могли бы вы щелкнуть символ галочки слева, чтобы отметить вопрос как решенный? - person halfer; 14.09.2015