'Event when a document is added to a calendar item
I want the event that will fire when a document is added to calendar item.
After that I want to handle that document by moving it to another place (network share).
I open the calendar and drag a Word document from Windows Explorer to a date on the calendar then I need that event to handle.
Code I tried:
Public WithEvents aaa As Outlook.AppointmentItem
Public WithEvents bbb As Outlook.DocumentItem
Public WithEvents ccc As Outlook.TaskItem
Public WithEvents ddd As Outlook.JournalItem
Public WithEvents eee As Outlook.Items
Private Sub aaa_AttachmentAdd(ByVal Attachment As Attachment)
End Sub
Private Sub aaa_BeforeAttachmentAdd(ByVal Attachment As Attachment, Cancel As Boolean)
End Sub
Private Sub bbb_AttachmentAdd(ByVal Attachment As Attachment)
End Sub
Private Sub bbb_BeforeAttachmentAdd(ByVal Attachment As Attachment, Cancel As Boolean)
End Sub
Private Sub ccc_AttachmentAdd(ByVal Attachment As Attachment)
End Sub
Private Sub ccc_BeforeAttachmentAdd(ByVal Attachment As Attachment, Cancel As Boolean)
End Sub
Private Sub ddd_AttachmentAdd(ByVal Attachment As Attachment)
End Sub
Private Sub ddd_BeforeAttachmentAdd(ByVal Attachment As Attachment, Cancel As Boolean)
End Sub
Private Sub eee_ItemAdd(ByVal Item As Object)
End Sub
Solution 1:[1]
I want to find a proper event that will fire when a document is added to calendar item.
It is not clear how a document is added to the Outlook item. Is it attached as a file? Or a shared link is added to the item?
Anyway, when users attach anything to Outlook items, they must select or open an item and then attach a file there. So, you can handle the SelectionChange event of the Explorer class to be aware which item is currently viewed or selected. And if any file is attached to the selected item you may handle the AppointmentItem.AttachmentAdd event which is when an attachment has been added to an instance of the parent object. The Attachment that was added to the item is passed as a parameter to the event handler.
You may find the Implement a wrapper for inspectors and track item-level events in each inspector article helpful.
If you want to track calendar item changes like shared links to documents added you need to handle the Items.ItemChange event which is fired when an item in the specified collection is changed.
Solution 2:[2]
Ah, I forgot the basic thing - to set those WithEvents variables in Application_ItemLoad:
Private Sub Application_ItemLoad(ByVal Item As Object)
If (TypeOf Item Is AppointmentItem) Then
Set aaa = Item
ElseIf (TypeOf Item Is DocumentItem) Then
Set bbb = Item
ElseIf (TypeOf Item Is TaskItem) Then
Set ccc = Item
ElseIf (TypeOf Item Is JournalItem) Then
Set ddd = Item
ElseIf (TypeOf Item Is Items) Then
Set eee = Item
ElseIf (TypeOf Item Is Explorer) Then
Set fff = Item
End If
End Sub
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Eugene Astafiev |
| Solution 2 | Dejan Dozet |
