如何在Outlook 2010 VBA中修改定期约会的属性(时区) [英] How to Modify Properties (Time Zone) of Recurring Appointments in Outlook 2010 VBA

查看:234
本文介绍了如何在Outlook 2010 VBA中修改定期约会的属性(时区)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在编写VBA Outlook宏的新修订版,它将通过用户日历中的所有约会,并将每个重复序列的时区更改为Central Standard.但是,无论我做什么,似乎都无法正确访问复发.目前,当我调试宏时,第一次调用ex.AppointmentItem.Subject(在定义重复模式rPattern之后的Debug.Print语句中)将失败.这里的中心问题是:如何一次访问和修改整个系列的定期约会?我是否可以a)修改主约会,b)遍历该系列中的所有约会(可能不会设置我将来需要的所有将来发生的事情),或者c)遍历异常集合并从那里修改重复发生?有人告诉我,遍历异常集合(尽管名称有误导性)是修改重复发生的唯一方法.这是正确的吗?

I am writing a new and revised version of a VBA Outlook macro that will go through all appointment's in a user's calendar and change every recurring series' time zone to Central Standard. No matter what I do, however, I cannot seem to get it to access the recurrence properly. At present, when I debug the macro it will fail the first time a call is made to ex.AppointmentItem.Subject (in the Debug.Print statement after the recurrence pattern rPattern is defined). The central question here is: how can I access and modify an entire series of recurring appointments at one time? Can I a) modify the master appointment, b) iterate through all appointments in the series (which may not set all future occurrences as I need it to), or c) iterate through the exceptions collection and modify the recurrence from there? I have been told that iterating through the exceptions collection (although misleading in name) is the only way to modify the recurrence. Is this correct?

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

I deeply appreciate any help you can provide, thanks!

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

Note: The aItem<>Null was commented out as a test, for some reason checking for a Null item (even tried Nothing keyword) always caused an error.

    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的后期绑定.

I was able to access all recurring appointments. See this sample. I am using late binding with 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

这篇关于如何在Outlook 2010 VBA中修改定期约会的属性(时区)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆