如果声明时间&用户定义的列

时间:2015-10-02 13:53:55

标签: vba outlook-vba

更新了代码3

我的新代码仅在没有+ ReceivedTime > 4

的情况下运行

我收到此声明的错误消息。错误是"运行时错误91,对象变量或未设置块变量"

到目前为止,逾期列仅填充了"否"因为4小时不包括在内。

我相信Debug.Print并不适合我想要删除的内容。

+ ReceivedTime > 4似乎无法确定ReceivedTime是否超过4小时?

For Each msg In myCollection
    '
    'check if received time is > than 4 hours
    If str2 = "A" Then
        'If str2 = "A" + ReceivedTime > 4 Then
        Set objProperty = msg.UserProperties(udf(4))
        objProperty.value = "Yes"'Set objProperty.str4 = "Yes" 'set Overdue column to say Yes

    Else
        Set objProperty = msg.UserProperties(udf(4))
        objProperty.value = "No" 'if this is not over 4 hours; display No
    End If

    msg.Save
Next
End If
End Sub

小时声明是否应该类似于以下

If str2 = "Create Customer" And ReceivedTime.MailItem = Hour > 4 Then 
    Set objProperty = msg.UserProperties(udf(4))
    objProperty.value = "Yes"

我也收到了运行时错误。

_________________________________________________________________________-

原始问题:

我希望Outlook中的用户定义字段列的If语句名为" Overdue"。

如果选择了一封电子邮件,其价值为" A"在UDF 2中,标志状态未标记为完成;然后有一个4小时的计时器来完成此任务 - 但是任务计时器应该在邮件项目到达邮箱时立即启动。

如果这没有过期,那么Column" Overdue"(UDF4)将保持为" No",如果这是过期的话; > 4小时后,此列将被设置为值"是"

以下是代码。

以前的代码

For Each msg In myCollection

    'check if received time is > than 4 hours
    If str2 = "A" + ReceivedTime > 4 Then
        msg.str4 = "Yes" 'set Overdue column to say Yes
    Else
        msg.str4 = "No"
    End If
    Debug.Print "Set objProperty"
    If (objProperty Is Nothing) Then
        Debug.Print "Set objProperty"
    End If
End If
Debug.Print "objProperty.value"
msg.Save
Next
End If  
End Sub

1 个答案:

答案 0 :(得分:1)

循环中应该有相同数量的If和End If语句。我没有得到你用objProperty做的事情,但不需要说明If End If结构。

For Each msg In myCollection

    If msg.FlagStatus = olFlagComplete Then

        'check if received time is > than 4 hours
        If str2 = "A" + TaskDueDate = ReceivedTime > 4 Then
            msg.str4 = "Yes" 'set Overdue column to say Yes
        Else
            msg.str4 = "No"
        End If

        Debug.Print "Set objProperty"
        'Set objProperty = msg.UserProperties(udf(4))

        If (objProperty Is Nothing) Then
            Debug.Print "Set objProperty"
            'Set objProperty = msg.UserProperties.Add(udf(4), olKeywords)
        End If

    End If 

    Debug.Print "objProperty.value"
    'objProperty.value = "No"`

    msg.Save

Next

End Sub