Have you ever tried to delete a document that is opened on your desktop (using NotesDocument.Remove(flag) method)? If you did, you probably received this error message: "Cannot remove NotesDocument when instantiated by NotesUIDocument". Use the following function to avoid this error message and delete the document.
Sub RemoveUIDOC(source As notesuidocument) Dim doc As notesdocument Dim unid As String Dim db As notesdatabase Set db = source.document. ParentDatabase unid = source.document.UniversalID Delete source Set doc = db.GetDocumentByUNID(unid) Call doc.Remove(True) End Sub