Outlook スケジューラ登録/保存時、当該イベントを捕捉するVBAコード
ThisOutlookSeesion
のドあたま
sample.vb
Public WithEvents myAppointment As Outlook.AppointmentItem
と記載。
次に、アイテムロード時ののイベントに、アポイントメントクラスの場合、当該クラスをセット
sample.vb
Private Sub Application_ItemLoad(ByVal Item As Object)
If Item.Class = olAppointment Then
Set myAppointment = Item
End If
End Sub
ほんで、以下に、スケジューラアイテム保存時の処理を書く。
myAppointmentは、毎回、解放してあげる必要がありそう。
sample.vb
Private Sub MyAppointment_Write(Cancel As Boolean)
' ここに必要な処理を書く
Set myAppointment = Nothing
End Sub
ちなみに、私は、以下のように使用。
(自分の勤務先仕様で?、他人主催者の会議体を、勝手に作れてしまい、かつその予定を、自分で変更できなくなってしまうことから(←むちゃくちゃ)、自分でエラーとして捕捉している。)
sample.vb
Private Sub MyAppointment_Write(Cancel As Boolean)
If InStr(1, myAppointment.Organizer, "【自分の名前】") > 0 Then
' OK
Else If myAppointment.Organizer = "" AND InStr(1, myAppointment.RequiredAttendees, "【自分の名前】") > 0 Then
' OK
Else
' NG
MsgBox "Organizer is " & myAppointment.Organizer & "_" & myAppointment.RequiredAttendees
Cancel = True
'myAppointment.Close olDiscard
End If
Set myAppointment = Nothing
End Sub