Create Outlook Event using VBA (Not an appointment!)

倾然丶 夕夏残阳落幕 提交于 2019-12-11 15:48:45

问题


So there is a thread SO Link Here that links how to make an outlook "event" but in reality it creates an appointment, not an event.

The differences can be read about HERE.

My question is simple... How do I create an actual event, not an appointment using VBA? Thanks!


回答1:


The different between Appointment and Event is Events lasts 24 hours or longer, as you know Events do not appear as occupied blocks of time in the user’s calendar. Instead, they appear as banners

To create an all-day event using vba, you will need to set the AllDayEvent property of the AppointmentItem object to true. Then set the Start property to 12:00 A.M. (midnight) on the day you want the event to begin, and End property to 12:00 A.M. on the day after you want the event to end.


VBA Example

Option Explicit
Public Sub Example()
    Dim Obj_Event As Outlook.AppointmentItem
    Set Obj_Event = Application.CreateItem(olAppointmentItem)

    With Obj_Event
        .Subject = "ALL Day Event Example"
        .Location = "stackoverflow.com"
        .AllDayEvent = True
        .Start = Format("03/10/2018 12:00 AM")
        .End = Format("03/11/2018 12:00 AM")
        .Save
        .Display
    End With
End Sub

C# Example

private void AllDayEventExample()
{
    Outlook.AppointmentItem appt = Application.CreateItem(
        Outlook.OlItemType.olAppointmentItem)
        as Outlook.AppointmentItem;
    appt.Subject = "Developer's Conference";
    appt.AllDayEvent = true;
    appt.Start = DateTime.Parse("6/11/2007 12:00 AM");
    appt.End = DateTime.Parse("6/16/2007 12:00 AM");
    appt.Display(false);
}

MSDN: How to: Create an Appointment That Is an All-Day Event



来源:https://stackoverflow.com/questions/49117785/create-outlook-event-using-vba-not-an-appointment

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!