LoginSignup
0
0

More than 3 years have passed since last update.

NotesとComコンポーネント

Posted at

Notesメールにはステーショナリーという機能があって、定型メールを登録しておくと、すぐに呼び出して利用できて便利だったのですが、Outlookだと、テンプレートという似た機能はあるのですが、操作の手間が多くて使いづらいので、Notesの標準テンプレートにあるノートブックで文書を書いて、その内容をOutlook経由で転送させるというものを書いてみました。

Sub Click(Source As Button)
'現在の文書を取得
    Dim ws As New NotesUIWorkspace
    Dim uidoc As NotesUIDocument
    Set uidoc = ws.CurrentDocument

'現在の文書を保存してフィールドの値を確定する         
    If Not uidoc.EditMode Then
        uidoc.EditMode = True
    End If
    Call uidoc.Save
    Call uidoc.Refresh

    Dim doc As NotesDocument
    Set doc = uidoc.Document

'送信済フラグが有効の場合は終了
    If doc.sendflg(0) = "1" Then
        Exit Sub
    End If

'Outlookを起動して、メールの内容をセットして送信する
    Dim OutlookObject As Variant
    Set OutlookObject = CreateObject("Outlook.Application")

    Dim ObjectItem As Variant
    Set ObjectItem = OutlookObject.CreateItem(0)

    With ObjectItem
        .To = "Yamada.Taro@XXXX.onmicrosoft.com"       'メール宛先
        .Subject = doc.GetItemValue("Subject")(0)   'メール件名
        .Body = doc.Body     'メール本文
    End With
    ObjectItem.Send

'送信済フラグを設定して閉じる
    Dim item As NotesItem
    Set item = doc.ReplaceItemValue( "sendflg", "1" )

    doc.SaveOptions = "0"
    Call doc.Save(True,ture)

    Call uidoc.Close(True)

End Sub

Comオブジェクト

ComオブジェクトはNotesでMicrosoftのアプリケーションを使いたいときに、メソッドやプロパティ込みで貸してくれる便利なヤツです。Notesと同世代の技術なので色々とお世話になってきました。ExcelはもちろんOffice製品は全てComで呼び出せます。

ただ、Notesと同世代の技術になるため、Edgeのような新しいMicrosoftのアプリケーションを呼び出すことはできません。ブラウザを呼び出すときは CreateObject(" InternetExplorer.Application") の一択です。もちろん、CromeやFireFoxのようなMicroSoft製品でないものは呼び出せません。
色々と複雑な処理をする場合は、バッチファイルを書いてからShell(バッチファイルまでのフルパス)みたいな使い方になります。

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