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

2019-07-30 17:57发布

我写一个VBA宏的Outlook将在用户的日历中经历的所有约会的和每一个反复出现的一系列时区更改为中部标准的一个新的修订版。 无论我做什么,但是,我似乎无法得到正常的访问复发。 目前,当我调试宏它会失败的第一次调用到ex.AppointmentItem.Subject做出(在Debug.Print语句复发模式rPattern定义后)。 这里的核心问题是:我怎么能访问和一次修改整个系列的定期约会的? 我可以一)修改主约会,b)透过该系列所有预约(这可能不是将所有的将来出现,因为我需要它)迭代,或c)通过收集例外从那里迭代和修改复发? 有人告诉我,通过异常集合迭代(虽然误导性名称)是修改复发的唯一途径。 它是否正确?

我深深感谢所有帮助您可以提供,谢谢!

注意:aItem <>空被注释了作为测试,由于某种原因,检查一个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

Answer 1:

我能够访问所有定期约会。 看到这个样品。 我使用与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


文章来源: How to Modify Properties (Time Zone) of Recurring Appointments in Outlook 2010 VBA