PDA

View Full Version : How to run a code after attachment file is fully opened on outlook itself?



Waleed_wwn
04-23-2022, 09:42 PM
(https://stackoverflow.com/posts/71984153/timeline) I need to run a code after I open attachment on outlook itself (either opened manually or by vba).
I tried to use AttachmentRead event ,
But I found out this event is triggered just after I double click on the attached file or using open from context menu (the attachment still not opened).
my need,to run a code after the attachment is fully opened by it's relative application.
In advance,grateful for all useful comments and answers.


Option Explicit
Option Compare Text
Public WithEvents MyItem As Outlook.MailItem

Private Sub Application_ItemLoad(ByVal Item As Object)
If Item.Class = olMail Then
Set MyItem = Item
End If
End Sub

Private Sub MyItem_AttachmentRead(ByVal Attachment As Attachment)
MsgBox ("This is a test message") 'This is a test code
End Sub

Maureene
09-19-2022, 02:26 AM
The best you can do is to track the MailItem.BeforeAttachmentWriteToTempFile event - but it is triggered both by opening and by previewing the attachment, and you won't know the file name unless you monitor the temp folder where Outlook creates the files.
Your best bet is to work with the application that actually opens the file.