VBAでNotesカレンダーを取得する
以前JavaでNotesカレンダーを取得してみました(JavaでNotesカレンダーの情報を取得する - 適材適所)が、今度はVBAでNotesカレンダーを取得してみたいと思います。
Notes操作をVBAで自動化したいという需要
そんな需要が、まだ、まだ、きっとまだ、あるはずだ!!ということでVBAによるNotes操作の第2弾です。
第一弾 VBAでNotesメールを取得する簡単なサンプル - 適材適所
今回はカレンダー
Notesにはカレンダー機能があり、スケジュール帳として使われ、またスケジュールの共有に使われたりしています、きっと、まだ。
今回はVBAでNotesカレンダーを取得する簡単なサンプルの紹介になります。
サンプルコード
早速サンプルコードの紹介です。定数を設定して、実行すると、イミディエイトウィンドウにNotesカレンダーの予定が出力されます。 参照設定で「Lotus Domino Object」のチェックを忘れないでください。
Option Explicit Sub printNotesCalendarList() Const PASSWORD As String = "環境に合わせて設定" Const SERVER As String = "環境に合わせて設定" Const NOTES_FILE As String = "環境に合わせて設定.nsf" 'セッションを確立 Dim notesSession As notesSession: Set notesSession = New notesSession notesSession.Initialize PASSWORD 'Notesのデータベースを取得 Dim notesDB As NotesDatabase: Set notesDB = notesSession.GetDatabase(SERVER, NOTES_FILE) 'カレンダーViewの取得 Dim view As NotesView: Set view = notesDB.GetView("$Calendar") 'カレンダーの最初の文書を取得 Dim notesDoc As NotesDocument: Set notesDoc = view.GetFirstDocument '全てのカレンダーにアクセスする Do Until (notesDoc Is Nothing) Dim subject As String: subject = notesDoc.GetItemValue("Subject")(0) Dim body As String: body = notesDoc.GetItemValue("Body")(0) '開始日時と終了日時のスマートな処理方法がわからず、無理やり処理しています。 On Error Resume Next Dim startDateTime As Date: startDateTime = notesDoc.GetItemValue("StartDateTime")(0) If Err.Description <> "" Then startDateTime = notesDoc.GetItemValue("StartDate")(0) End If Err.Clear Dim endDateTime As Date: endDateTime = notesDoc.GetItemValue("EndDateTime")(0) If Err.Description <> "" Then endDateTime = notesDoc.GetItemValue("EndDate")(0) End If On Error GoTo 0 Dim location As String: location = notesDoc.GetItemValue("Location")(0) Dim form As String: form = notesDoc.GetItemValue("Form")(0) Debug.Print "タイトル:" & subject Debug.Print "内容:" & body Debug.Print "開始日:" & startDateTime Debug.Print "終了日:" & endDateTime Debug.Print "場所:" & location Debug.Print "タイプ:" & form Debug.Print "---------------------------------" '次の文書を取得する Set notesDoc = view.GetNextDocument(notesDoc) Loop End Sub
これを使うことで、VBAを使ってGoogleカレンダーと同期したりといったことが可能になるかと思います。
お読みいただき、ありがとうございました。