【发布时间】:2021-01-11 15:04:47
【问题描述】:
我正在尝试阅读我的 Sharepoint 日历条目,然后在我的个人日历中添加一个在同一天 4 小时的节日。
以下创建了一个新条目,但我的 For Each 循环似乎不起作用,因为当我尝试使用从变量“newStart”读取的日期和时间创建一个新条目时,它总是跳回主函数。
Public newStart As String
Sub ReadEntries()
Dim oApp As Outlook.Application
On Error Resume Next
' check if Outlook is running
Set oApp = GetObject("Outlook.Application")
If Err <> 0 Then
'if not running, start it
Set oApp = CreateObject("Outlook.Application")
End If
Set olApp = New Outlook.Application
Set olFldr = olApp.GetNamespace("MAPI").Folders("Other Calendars").Folders("FOLDERNAME")
For Each Items In olFldr
If olFldr.Items.Subject = "Given Entry Title" Then
newStart = olFldr.Items.Start
CreateStandby
End If
Next
Set oObject = Nothing
Set oApp = Nothing
End Sub
Sub CreateStandby()
Dim standbyEntry As Object
Set standbyEntry = Application.CreateItem(olAppointmentItem)
standbyEntry.Subject = "New Entry Title"
standbyEntry.Start = newStart
standbyEntry.Duration = 240
standbyEntry.BusyStatus = olOutOfOffice
standbyEntry.Send
standbyEntry.Save
End Sub
【问题讨论】:
-
认为模块顶部的
Option Explicit是强制性的。