0

我想更改 Outlook 2010 日历中所有项目的时区。

我对在循环中迭代时如何处理集合中的项目感到困惑。我的主要背景是Java,据我所知,循环中有一个变量用作虚拟变量,它将依次获取集合中所有项目的值。这种 FOR 循环通常不需要特殊分配。您是否需要以某种方式手动推进变量以保持循环继续进行?

这是我的代码:

Public Sub TZFix()

    Dim oAppointmentItem As Outlook.AppointmentItem
    Dim tzs As Outlook.TimeZones
    Dim tzCentral As Outlook.TimeZone
    Dim oAppointments As Object
    Dim oNS As Outlook.NameSpace

    Set oNS = oOutlook.GetNamespace("MAPI")
    Set oAppointments = oNS.GetDefaultFolder(olFolderCalendar)
    Set tzs = Application.TimeZones
    Set tzCentral = tzs("Central Standard Time")

    For Each oAppointmentItem In oAppointments.Items
        Set oAppointmentItem.StartTimeZone = tzCentral
        Set oAppointmentItem.EndTimeZone = tzCentral
    Next

End Sub

我相信循环中的变量分配存在问题,因为Error 91: Object Variable or With block variable not set每当我运行它时都会出错。

4

3 回答 3

0

我的脚本中也有这个问题。对我来说,解决方案是将 Macro-Security-Settings 设置为最低并再次运行它并且它起作用了。也许值得一试!

于 2014-05-13T09:35:19.107 回答
0

oOutlook从未分配给,因此是Nothing。您可能打算将其设置为Application.

此外,将局部变量设置Nothing为最后是多余的,请删除它。

于 2012-06-29T18:31:59.457 回答
0

我使代码只对您的代码进行了少量更改。这是有效的:

Public Sub TZ_change_to_Hawaii()
''''Changing  the selected appointments' time zones to Hawaii

Dim tzs As Outlook.TimeZones
Dim tzCentral As Outlook.TimeZone

Set tzs = Application.TimeZones
Set tzCentral = tzs("Hawaiian Standard Time")

Dim objOL As Outlook.Application
Dim objSelection As Outlook.Selection
Dim objItem As Object

Set objOL = Outlook.Application
Set objSelection = objOL.ActiveExplorer.Selection

For Each objItem In objSelection
    Set objItem.StartTimeZone = tzCentral
    Set objItem.EndTimeZone = tzCentral
    objItem.Save
Next
End Sub
于 2017-08-12T10:41:20.753 回答