将外出约会添加到所选日期

时间:2019-06-19 14:49:17

标签: vba outlook

我知道使用VBA,您可以在代码中设置日期和时间的约会添加到Outlook日历中,但我要做的就是在所选日期的7:00至9:30之间将约会添加到日历中。是否可以在选定的日期使用VBA并让其不在办公室状态?

我找到了以下代码,但这会将事件添加到所选时间,而不是所选日期的特定时间:

Sub CreateAppointmentUsingSelectedTime() 
    Dim datStart As Date 
    Dim datEnd As Date 
    Dim oView As Outlook.view 
    Dim oCalView As Outlook.CalendarView 
    Dim oExpl As Outlook.Explorer 
    Dim oFolder As Outlook.folder 
    Dim oAppt As Outlook.AppointmentItem 
    Const datNull As Date = #1/1/4501# 

    ' Obtain the calendar view using 
    ' Application.ActiveExplorer.CurrentFolder.CurrentView. 
    ' If you use oExpl.CurrentFolder.CurrentView, 
    ' this code will not operate as expected. 
    Set oExpl = Application.ActiveExplorer 
    Set oFolder = Application.ActiveExplorer.CurrentFolder 
    Set oView = oExpl.CurrentView 

    ' Check whether the active explorer is displaying a calendar view. 
    If oView.ViewType = olCalendarView Then 
        Set oCalView = oExpl.currentView 
        ' Create the appointment using the values in 
        ' the SelectedStartTime and SelectedEndTime properties as 
        ' appointment start and end times. 
        datStart = oCalView.SelectedStartTime 
        datEnd = oCalView.SelectedEndTime 
        Set oAppt = oFolder.items.Add("IPM.Appointment") 
        If datStart <> datNull And datEnd <> datNull Then 
            oAppt.Start = datStart 
            oAppt.End = datEnd 
        End If 
        oAppt.Display 
    End If 
End Sub

欢呼

2 个答案:

答案 0 :(得分:0)

是的,有可能。有三种在Outlook中创建新约会项目的方法。在How To: Create a new Outlook Appointment item文章中详细了解它们。

看起来您只需要设置StartEnd属性:

oAppt.Start = #7/7/2019 8:00:00 AM# 
oAppt.End = #7/7/2019 11:00:00 AM# 

答案 1 :(得分:0)

我已经这样做了。不知道这是否是最好的方法,但是否可行:

tableBEntries