0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Outlook VBAで、スケジューラ設定する時の 保存時のイベントを捕捉したい

Posted at

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
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?