使用 excel vba 创建培训预约并将其附加到 Outlook 中的通知电子邮件中

问题描述 投票:0回答:1

我编写了一个向学员发送通知的程序,并尝试编写一个代码来创建约会 (.ics),以在开始课程的一天之前提醒他们培训课程,然后将约会 (.ics) 附加到电子邮件,以便他们可以将其添加到日历中,但代码不起作用,向我显示的错误消息是“需要对象”

Sub sendMail()


Dim ol As Outlook.Application
Dim olm As Outlook.MailItem

Dim Appoint As Outlook.AppointmentItem   ' create the appointment item

Set ol = New Outlook.Application


Set olm = ol.CreateItem(olMailItem)
Set Appoint = ol.CreateItem(olAppointmentItem)
    
''''''''''' create the appointment
    With olp

     .Subject = "test subject"
     .Location = "test location"
     .Start = "06/01/2020 05:30 PM"
     .End = "06/01/2020 06:30 PM"
     .RequiredAttendees = "[email protected]"
     .OptionalAttendees = "[email protected]"
     .Body = "test body"
     
     .SaveAs ActiveWorkbook.Path & "\test_subject.oft"
            


    End With
    
    With olp
    
        .Subject = Sheet1.Cells(r, 6).Value
        .Location = Sheet1.Cells(r, 15).Value
        .Start = Sheet1.Cells(r, 8).Value
        .End = Sheet1.Cells(r, 9).Value
        
        .RequiredAttendees = Sheet1.Cells(r, 4).Value
        .ReminderMinutesBeforeStart = 4320
        .OptionalAttendees = "[email protected]"
        .Body = "test body"
         
        .SaveAs ActiveWorkbook.Path & "\test_subject.ics", OlSaveAsType.olICal
         
    
    
       End With
    


    Set olm = Nothing
    

MsgBox "Notifications have been sent successfully", vbOKOnly + vbInformation, "Status"
End Sub
excel vba calendar email-attachments appointment
1个回答
0
投票

这对我有用:

Sub sendMail()

    Dim ol As Outlook.Application
    Dim olm As Outlook.MailItem
    Dim Appoint As Outlook.AppointmentItem, fName As String
    
    fName = ThisWorkbook.path & "\appointment.ics"
    
    Set ol = New Outlook.Application
    Set Appoint = ol.CreateItem(olAppointmentItem)
    With Appoint
        .Subject = "test subject"
        .Location = "test location"
        .Start = "06/01/2020 05:30 PM"
        .End = "06/01/2020 06:30 PM"
        .RequiredAttendees = "[email protected]"
        .OptionalAttendees = "[email protected]"
        .Body = "test body"
        .SaveAs fName, OlSaveAsType.olICal
    End With
    
    Set olm = ol.CreateItem(olMailItem)
    With olm
        .Subject = "subject"
        .Body = "test body"
        .Attachments.Add fName
        .Display
   End With
    
End Sub
© www.soinside.com 2019 - 2024. All rights reserved.