如何检查Outlook VBA中是否有任何移动?

时间:2016-01-11 01:15:35

标签: vba outlook outlook-vba

代码如下:

Sub olFromSysItems_ItemAdd(ByVal item As Object)

    Dim EventMessage As String
    Dim strErrMessage As String
    Dim objMailFromSys As clsMailFromSys

On Error GoTo Error_Handler

    Set objMailFromSys = New clsMailFromSys
    objMailFromSys.SetMailObject item

    If objMailFromSys.Function1(strErrMessage) = False Then
       GoTo Error_Handler
    End If

    If objMailFromSys.Function2(strErrMessage) = False Then
        GoTo Error_Handler
    End If

    If objMailFromSys.Function3(strErrMessage) = False Then
        GoTo Error_Handler
    End If

    item.Move folderFromSys_Processed
    Set objMailFromSys = Nothing
    Exit Sub

Error_Handler:

    EventMessage = "Error email from " & item.SenderName & "." & Chr(12)
    If Len(Trim(strErrMessage)) = 0 Then
        EventMessage = EventMessage & "olFromSysItems_ItemAdd Error: " & Err.Description & Chr(12)
    Else
        EventMessage = EventMessage & strErrMessage & Chr(12)
    End If
    EventMessage = EventMessage & "Please also check the email folder Error"
    EventMessage = Chr(34) & EventMessage & Chr(34)

    LogEvent EventMessage
    Set objMailFromSys = Nothing
    item.Move folderError

    SendErrorMessageToAdmin "Error Email from VBA", EventMessage, item

End Sub

偶尔会出现以下行的错误:

item.Move folderError

出现以下错误消息:

  

由于原始项目,项目被复制而不是移动   无法删除。无法删除该项目。它被移动或已被删除,或访问被拒绝。

我的问题:

  1. 如何检查Outlook VBA中是否有任何内容?
  2. 如何检查我是否无法将项目移动到Outlook VBA中的文件夹?

1 个答案:

答案 0 :(得分:0)

如果你还没有找到另一种方法,那么绕过这个错误就可以了。

' Use only for a specific purpose
On Error Resume Next
item.Move folderError
' Turn error bypass off once the purpose for it has been served
On Error GoTo 0