如何在Outlook 2010 VBA中修改定期约会的属性(时区)



我正在编写VBA Outlook宏的新版本和修订版,该宏将遍历用户日历中的所有约会,并将每个定期系列的时区更改为中央标准。然而,无论我做什么,我似乎都无法让它正确地访问复发。目前,当我调试宏时,它将在第一次调用ex时失败。AppointmentItem.Subject(在定义重复模式rPattern后的debug.Print语句中)。这里的核心问题是:如何一次访问和修改一系列定期约会?我可以a)修改主约会,b)迭代系列中的所有约会(可能不会根据我的需要设置未来的所有约会),或者c)迭代异常集合并从那里修改重复吗?有人告诉我,遍历异常集合(尽管名称上有误导性)是修改重复周期的唯一方法。这是正确的吗?

我非常感谢你能提供的任何帮助,谢谢!

注意:项目<>Null被注释为测试,由于某些原因,检查Null项(甚至尝试了Nothing关键字)总是会导致错误。

    Public Sub IterateAll()
   Dim olApp As New Outlook.Application
   Dim aObject As Object
   Dim calCollection As Outlook.Items
   Dim tzs As Outlook.TimeZones
   Dim tzCentral As Outlook.TimeZone
   Dim tzUTC As Outlook.TimeZone
   Dim olNameSpace As Outlook.NameSpace
   Dim rPattern As Outlook.RecurrencePattern
   Dim ex As Outlook.Exception

   Dim s As Outlook.TimeZone
   Dim e As Outlook.TimeZone

   Set olNameSpace = olApp.GetNamespace("MAPI")
   Set calCollection = olNameSpace.GetDefaultFolder(olFolderCalendar).Items
   Set tzs = Application.TimeZones
   Set tzCentral = tzs("Central Standard Time")
   Set tzUTC = tzs("UTC")
   For Each aObject In calCollection
       If aObject.IsRecurring Then
           Set rPattern = aObject.GetRecurrencePattern

           Debug.Print ("Subject: " + aObject.Subject)
           Debug.Print ("Old Time Zone is " & aObject.StartTimeZone)
           aObject.StartTimeZone = tzCentral
           aObject.EndTimeZone = tzCentral
               Debug.Print ("New Time Zone is " & aObject.StartTimeZone)
           aObject.Save
        End If
       Next
    End Sub

我能够访问所有定期约会。请参阅此示例。我正在使用Outlook的后期绑定。

Option Explicit
Const olFolderCalendar = 9
Sub Sample()
    Dim oOlAp As Object, oOlns As Object, oOlfld As Object
    Dim colItems As Object, colFilteredItems As Object
    Dim oOlpatrn As Object, objItem As Object
    Set oOlAp = CreateObject("Outlook.Application")
    Set oOlns = oOlAp.GetNamespace("MAPI")
    Set oOlfld = oOlns.GetDefaultFolder(olFolderCalendar)
    Set colItems = oOlfld.Items
    Set colFilteredItems = colItems.Restrict("[IsRecurring] = TRUE")
    For Each objItem In colFilteredItems
        Set oOlpatrn = objItem.GetRecurrencePattern
        If oOlpatrn.PatternEndDate > Now Then
            Debug.Print objItem.Subject
        End If
    Next
End Sub

跟进

Const olFolderCalendar = 9
Sub Sample()
    Dim oOlAp As Object, oOlns As Object, oOlfld As Object
    Dim colItems As Object, colFilteredItems As Object
    Dim oOlpatrn As Object, objItem As Object
    Dim tzs As Object, tzCentral As Object
    Set oOlAp = CreateObject("Outlook.Application")
    Set oOlns = oOlAp.GetNamespace("MAPI")
    Set oOlfld = oOlns.GetDefaultFolder(olFolderCalendar)
    Set colItems = oOlfld.Items
    Set colFilteredItems = colItems.Restrict("[IsRecurring] = TRUE")
    Set tzs = Application.TimeZones
    Set tzCentral = tzs("Central Standard Time")
    For Each objItem In colFilteredItems
        Set oOlpatrn = objItem.GetRecurrencePattern
        If oOlpatrn.PatternEndDate > Now Then
            Debug.Print "Old Time Zone is " & objItem.StartTimeZone
            objItem.StartTimeZone = tzCentral
            Debug.Print "New Time Zone is " & objItem.StartTimeZone
            objItem.Save
        End If
    Next
End Sub

相关内容

  • 没有找到相关文章

最新更新