добавить встречу вне офиса в выбранный день - PullRequest
0 голосов
/ 19 июня 2019

Я знаю, что с 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 голосов
/ 21 июня 2019

Я сделал это таким образом. не уверен, что это лучший способ, но он работает:

Sub addSchoolRunToCalendar()
    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#

    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

        datStart = oCalView.SelectedStartTime
        datStart = Format(datStart, "dd/mm/yyyy") & " " & Format("07:00", "hh:mm")

        Set oAppt = oFolder.Items.Add("IPM.Appointment")
        If datStart <> datNull And datEnd <> datNull Then
            oAppt.Subject = "School Run"
            oAppt.Location = "Home"
            oAppt.BusyStatus = olOutOfOffice
            oAppt.Start = datStart
            oAppt.Duration = "150"
            oAppt.ReminderSet = False
        End If

        oAppt.Save

    End If

End Sub
0 голосов
/ 19 июня 2019

Да, это возможно.Существует три способа создания нового элемента встречи в Outlook.Подробнее о них см. В Как: создать новый элемент назначения Outlook статья.

Похоже, вам просто нужно установить свойства Start и End:

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