Using Events with Automationは、オートメーションでOutlookイベントを使用する方法を説明しています。私はしかし、私のプロジェクトにそのコードを実装する方法を理解していない。Outlookイベントをオートメーションで使用する
私はInspector.BeforeMinimize Event (Outlook)
で説明したようにInspectorBeforeMinimizeEvent
メソッドを使用したいときはいつでも、ユーザーの移動/サイズ変更さ/最大/そしてMessageBox
がポップアップする必要があり、手動でインスペクタを最小限に抑えることができます。
次のコードは、テストのためのものである:
Imports Microsoft.Office.Interop
Public Class Form1
Public WithEvents myIns As Outlook.Inspector
Private Sub Form1_Load(sender As Object, e As System.EventArgs) Handles Me.Load
Process.Start("Outlook.exe")
Threading.Thread.Sleep(3000)
Dim olApp As New Outlook.Application
Dim myMailItem As Outlook.MailItem
myMailItem = CType(olApp.CreateItem(Outlook.OlItemType.olMailItem), Outlook.MailItem)
myMailItem.Subject = "Hello"
myMailItem.To = "[email protected]"
myMailItem.Body = "Hi there..."
Dim myIns As Outlook.Inspector
myIns = myMailItem.GetInspector
myIns.Display(False)
Dim myWord As Word.Document
myWord = CType(myIns.WordEditor, Word.Document)
Dim mySel As Word.Selection
mySel = myWord.Application.Selection
Threading.Thread.Sleep(10000)
'Following line just for testing. Normally following line doesnt exist in my original code. The real scenario is the user minimizes the inspector manually.
myIns.WindowState = Outlook.OlWindowState.olMinimized
myWord.InlineShapes.AddPicture(FileName:="C:\Example.png", LinkToFile:=False, SaveWithDocument:=True, Range:=mySel.GoTo(What:=Word.WdGoToItem.wdGoToLine, Which:=Word.WdGoToDirection.wdGoToLast, Count:=-4))
'myMailItem.Send()
End Sub
End Class
イベントコード:
Private Sub myIns_BeforeMinimize(Cancel As Boolean)
MessageBox.Show("You are minimizing this inspector.", "Title", MessageBoxButtons.OK, MessageBoxIcon.Information, MessageBoxDefaultButton.Button1, MessageBoxOptions.DefaultDesktopOnly)
End Sub
があなたの投稿をvandalizeないでください:
あなたのコードは次のようになります。 Stack Exchangeネットワーク上に掲載することで、SEがそのコンテンツを配布する権利(CC BY-SA 3.0ライセンス)(https://creativecommons.org/licenses/by-sa/3.0 /))。 SEのポリシーによって、どんな破壊行為も元に戻ります。この投稿とアカウントとの関連付けを解除する場合は、[解約リクエストの正しいルートは何ですか?](https://meta.stackoverflow.com/q/323395)を参照してください。 – Bugs