タイトルで述べたように、Outlookでアイテムを削除するのを防止しようとしています。私はBeforeItemMoveイベントで操作をキャッチすることができます。その後、ユーザは、続行するかキャンセルするかの選択肢が与えられる。彼が進めることを決定した場合、そのアイテムは「削除済みアイテム」フォルダに移動され、永久に削除されません。Outlookでハード削除されたアイテムをVBAを使用して削除済みアイテムにリダイレクトする
私の最初のアイデアは、キャンセル操作をTrueに設定してアイテムを[削除済みアイテム]フォルダに移動することで、削除操作をキャンセルすることでした。問題は、移動操作のために再びイベントが発生することですが、手渡されたアイテムオブジェクトは何とか壊れているようです。私は、削除されたアイテムにUserPropertyを設定して、それを移動しようとしました。しかし、私は小道具を読むしようとするイベントサブの "第二の実行"で、私は、メッセージが見つかりませんでしたランタイムエラーを取得します。
Can S.O.助けて?ここで
が関与する2つのイベントハンドラです:Private Sub oTasks_BeforeItemMove(ByVal Item As Object, ByVal MoveTo As Folder, Cancel As Boolean)
Dim shouldDelete As Boolean
shouldDelete = False
Dim hardDeletePerformed
hardDeletePerformed = False
If (MoveTo Is Nothing) Then
shouldDelete = True
hardDeletePerformed = True
ElseIf (g_oNS.CompareEntryIDs(MoveTo.EntryID, oDeletedItems.EntryID)) Then
shouldDelete = True
End If
Dim oTask As TaskItem
Set oTask = Item
If shouldDelete Then
If (InStr(1, oTask.Subject, "frist", vbTextCompare)) Then
Dim message As String
message = "..."
Dim res As VbMsgBoxResult
res = MsgBox(message, vbOKOnly + vbCritical, "Compliance-Warnung!")
Cancel = True
Else
Dim message2 As String
message2 = "..."
Dim res2 As VbMsgBoxResult
res2 = MsgBox(message2, vbYesNo + vbCritical, "Compliance-Warnung!")
If (res2 = vbYes) Then
Cancel = False
If hardDeletePerformed Then
oTask.Move oDeletedItems
Cancel = True
End If
Else
Cancel = True
End If
End If
End If
End Sub
Private Sub oAppointments_BeforeItemMove(ByVal Item As Object, ByVal MoveTo As Folder, Cancel As Boolean)
If inProgress Then
Cancel = True
inProgress = False
Else
Dim shouldDelete As Boolean
shouldDelete = False
Dim hardDeletePerformed
hardDeletePerformed = False
If (MoveTo Is Nothing) Then
shouldDelete = True
hardDeletePerformed = True
ElseIf (g_oNS.CompareEntryIDs(MoveTo.EntryID, oDeletedItems.EntryID)) Then
shouldDelete = True
End If
Dim oAppointment As AppointmentItem
Set oAppointment = Item
If shouldDelete Then
If (InStr(1, oAppointment.Subject, "frist", vbTextCompare)) Then
Dim message As String
message = "..."
Dim res As VbMsgBoxResult
res = MsgBox(message, vbOKOnly + vbCritical, "Compliance-Warnung!")
Cancel = True
Else
Dim message2 As String
message2 = "..."
Dim res2 As VbMsgBoxResult
res2 = MsgBox(message2, vbYesNo + vbCritical, "Compliance-Warnung!")
If (res2 = vbYes) Then
Cancel = False
If hardDeletePerformed Then
inProgress = True
oAppointment.Move oDeletedItems
oAppointment.Save
'inProgress = False
Cancel = True
End If
Else
Cancel = True
End If
End If
End If
End If
End Sub
奇妙なことがあるが、oTasksのための最初のEventHandlerはまさに私はそれがしたいように動作します。アイテムは削除されたアイテムに移動され、イベントハンドラは一度だけ呼び出されます。 2番目のoAppointmentsは、Timの提案なしにinProgress-if-clause ...を呼び出さなくてはならず、2番目のイベントハンドラでは、アイテムはDraftsに移動され、Deleted ItemsではなくoDeletedItems-Objectその間に変更されていない...任意のアイデア?
PS:私はVBAが嫌です!
常に実際のコードを表示するのに役立ちます... –