If you ever tried to manipulate attachments within RTF emails then you are probably aware of this weird issue. Say you have 4 attachments in the email body of a RTF email. Now if you programmatically tries to delete those attachments and place new attachments to their original location then you will see how messy it could be.
The attachments loose their position and can be placed anywhere in the body. So whom to blame? The code.. really? Not exactly but yes to code. This is a weird timing issue and we still do not know the real root cause of the problem. But the below code can do the job for you.
Dim oItem As Object
Dim oAttachments As Outlook.Attachments
Dim iCount As Integer
Dim i As Integer
Const sAttPath = "C:\"
Set oItem = Application.ActiveInspector.CurrentItem
Set oAttachments = oItem.Attachments
iCount = oAttachments.Count
If iCount > 0 Then
' Remove all attachments
For i = iCount To 1 Step -1
arrPos(i) = oAttachments(i).Position
arrPath(i) = sAttPath & "Restored_" & oAttachments.Item(i).FileName
' Add back attachments in original positions
For i = 1 To iCount
oItem.Attachments.Add arrPath(i), , arrPos(i)
Please do let me know if you face any problems with this code.
"To ensure consistent results, always save an item before adding or removing objects in the Attachments collection of the item."
Instead we decided to create a common tag among all our common Exchange and Outlook developer support blogs posts (DevMsgTeam) so that there is one URL for all the posts on the team. Enjoy!
The feed will aggregate here.
You can subscribe to the RSS feed here.