So I want to edit my received mails afterwards to add links. If the emails have been received as plain text or HTML I have just edited the appropriate msg.Body or msg.HTMLBody.
I was facing exactly the same issue (Outlook VBA: Replace inline object with text).
As posted in my comment (soon to be edited to a more polished version, after further testing), you have to use objDoc.UnProtect
prior to modifying contents.
I have actually used
'On Error Resume Next ' This will prevent the error message... risky!
Dim odProt As Integer
odProt = objDoc.ProtectionType
If (odProt <> wdNoProtection) Then
Debug.Print "Document is protected with type " & odProt & ", unprotecting temporarily"
objDoc.UnProtect
End If
' ... Write your code
If (odProt <> wdNoProtection) Then
Debug.Print "Restoring protection"
objDoc.Protect (odProt)
End If
objMsg.Display
objMsg.Save
I am not sure if the last two lines are the best, but it worked for me.
Note that having On Error Resume Next
will prevent the error message, and you may see that none of your editions has any effect without apparent reason.