Extracting file embedded in rich text

I’m using a profile document with a few rich text item to store xsl transformation files. These are used to transform xml content stored in the documents into xsl:fo and html. The files are inserted in the profile doc by drag and drop from the file system.The transformation process initially tries to extract the transformation file on disk using the following sub:

( 1) Sub ExportTransformation(transfItemName As String, transfFileName As String)

( 2)

( 3) Dim session As New NotesSession

( 4) Dim profileDoc As NotesDocument

( 5)

( 6) Set profileDoc = session.CurrentDatabase.GetProfileDocument(PROFILE_DOC)

( 7)

( 8) 'get the desired transformation item

( 9) Dim docItem As NotesRichTextItem

(10) Set docItem = profileDoc.GetFirstItem(transfItemName)

(11)

(12) If Not (docItem Is Nothing) Then

(13) Dim attachmentObj As NotesEmbeddedObject

(14) Set attachmentObj = docItem.EmbeddedObjects(0)

(15) Call attachmentObj.ExtractFile(transfFileName)

(16) End If

(17)End Sub

The issue is that the process sometimes fails with the error message “Variant does not contain a container” at line (14), and if I check the EmbeddedObjects property with the debugger it is empty. I noticed that if close, compress and reload the database it works again, until I replace the transformation files.

Does anybody know why it happens and how to get around the problem?

Many thanks.