Can add/modify the attachment in documentitem during OutlookAppEvents_ItemLoad event ?

Add-in Express™ Support Service
That's what is more important than anything else

Can add/modify the attachment in documentitem during OutlookAppEvents_ItemLoad event ?
the item will be loading from the server when it is selected  
alvin chan




Posts: 34
Joined: 2019-10-07
Dear Support

As per subject , can I add/modify the attachment in one document item when it is selected in item OutlookApp load event ?
Posted 21 Oct, 2019 05:27:09 Top
Andrei Smolin


Add-in Express team


Posts: 18830
Joined: 2006-05-11
Hello Alvin,

No. at https://docs.microsoft.com/en-us/office/vba/api/outlook.application.itemload, they write: This event occurs when the Outlook item begins to load into memory. Data for the item is not yet available, other than the values for the Class and MessageClass properties of the Outlook item, so an error occurs when calling any property other than Class or MessageClass for the Outlook item returned in Item.


Andrei Smolin
Add-in Express Team Leader
Posted 21 Oct, 2019 07:21:48 Top
alvin chan




Posts: 34
Joined: 2019-10-07
Hi Andrei,

In that case, what do you advise ? our goal is to once user select the documentitem, then only we download and add the attachment into it.
Posted 21 Oct, 2019 20:29:15 Top
Andrei Smolin


Add-in Express team


Posts: 18830
Joined: 2006-05-11
Hello Alvin,

Do you want to prevent the user from attaching anything to the selected email?


Andrei Smolin
Add-in Express Team Leader
Posted 22 Oct, 2019 05:05:50 Top
alvin chan




Posts: 34
Joined: 2019-10-07
Hi andrei

I have figure out how to attach the item to document item programmatically, however after I add the attachment, the reading pane didnt refresh the new content, i have to click the item again to view the changes on the reading pane . Code as below

    DocuItem.Attachments.Add("c:Technical Manual_2018AUG01.docx")
         DocuItem.MessageClass = "ipm.document.word.document.12"
   DocuItem.Save()


Please advise how to make the reading pane auto refresh
Posted 22 Oct, 2019 05:18:23 Top
Andrei Smolin


Add-in Express team


Posts: 18830
Joined: 2006-05-11
I would try to use Explorer.ClearSelection and Explorer.AddToSelection methods; these are available since Outlook 2010.

DocuItem.Attachments.Add("c:Technical Manual_2018AUG01.docx")


This code lines creates and leaves unreleased two COM objects:
1) DocuItem.Attachments returns a COM object representing a collection of attachments in the given Outlook item
2) Attachments.Add() returns a COM object representing the attachment added

Leaving a COM object unreleased my cause numerous and various issues that is difficult to reproduce and investigate. I strongly recommend that you check section Releasing COM Objects at https://www.add-in-express.com/docs/net-office-tips.php#releasing and follow these recommendations.


Andrei Smolin
Add-in Express Team Leader
Posted 22 Oct, 2019 06:16:34 Top
alvin chan




Posts: 34
Joined: 2019-10-07
HI Andrei

Refer to this : https://docs.microsoft.com/en-us/office/vba/api/outlook.explorer.addtoselection

If the specified item is already selected in the active explorer, calling AddToSelection does not result in any change to the selection, and the SelectionChange event does not fire.


how to i force the selection change event fire if I add the currently selected item in the active explorer to the "addtoselection "
Posted 22 Oct, 2019 11:23:46 Top
alvin chan




Posts: 34
Joined: 2019-10-07
Dear Andrei

Please ignore, I found the solution already, by using Outlook.View
Posted 22 Oct, 2019 11:42:53 Top
Andrei Smolin


Add-in Express team


Posts: 18830
Joined: 2006-05-11
No problem.


Andrei Smolin
Add-in Express Team Leader
Posted 23 Oct, 2019 02:59:18 Top