Soll die Routine ImportNewerAttachment aufgerufen werden. Hier der Code dazu.
Sub ImportNewerAttachment()
Dim ws As NotesUIWorkspace
Dim Source As NotesUIDocument
Dim fso As Variant
Dim doc As NotesDocument
Dim varFile As Variant
Dim item As NotesItem
Dim rtitem As NotesRichTextItem
Dim eo As NotesEmbeddedObject
Set ws=New NotesUIWorkspace
Set Source=ws.CurrentDocument
Set doc=source.Document
If doc.HasItem("DateLastModified") Then
Set fso=createobject("Scripting.FileSystemObject")
Set varFile=fso.getFile(doc.FilePath(0))
If Not varFile.DateLastModified=doc.DateLastModified(0) Then
AddAttachment ws,"frmNeedAnalysis","fdAttachment",doc.FilePath(0)
Set doc=ws.CurrentDocument.Document
Print "Neu Importiert!"
' doc.ReplaceItemValue "DateLastModified", varFile.DateLastModified
' doc.ReplaceItemValue "FilePath", FileName
' doc.RemoveItem "DateLastModified"
' doc.RemoveItem "FilePath"
End If
'Print Source.Document.DateLastModified(0)
End If
End Sub
Sub AddAttachment(uiws As NotesUIWorkspace, FormName As String,ItemName As String,FileName As String)
Dim uidoc As NotesUIDocument
Dim ws As New NotesUIWorkspace
Dim thisdoc As NotesDocument
Dim rtitem As NotesRichTextItem
Dim olduidoc As NotesUIDocument
Set olduidoc=uiws.CurrentDocument
Set thisdoc = uiws.CurrentDocument.Document ' doc in memory but hasn't been saved yet
thisdoc.RemoveItem ItemName
Set rtitem = New NotesRichTextItem (thisdoc,ItemName)
rtitem.EmbedObject EMBED_ATTACHMENT, "", FileName
rtitem.Update
thisdoc.Form=FormName
' set the SaveOptions field so that when the uidoc is closed, the user won't be asked to save
thisdoc.SaveOptions = "0"
' close the uidoc. It won't actually happen until the code is finished executing
olduidoc.Close True
' create a new uidoc and open the backend doc that is still in memory with added doc link
Set uidoc = uiws.EditDocument(True, thisdoc)
' delete the reference to the old uidoc
' this is necessary because the code below affects it if left in memory
Delete olduidoc
' re-associate the variable with the backend doc
' have to do this because the olduidoc reference was deleted
Set thisdoc = uidoc.Document
' remove the SaveOptions field so the doc can be saved
thisdoc.RemoveItem "SaveOptions"
uidoc.Refresh
End Sub
Damit nach der Routine EditAttachment das Zeug wieder importiert wird.
Sub EditAttachment
Dim ws As NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim doc As NotesDocument
Dim item As NotesItem
Dim rtitem As NotesRichTextItem
Dim strFileName As String
Dim fso As Variant
Dim wsh As Variant
Dim varFile As Variant
Dim ret As Variant
Set ws=New NotesUIWorkspace
Set uidoc=ws.CurrentDocument
Set doc=uidoc.Document
Set item=doc.GetFirstItem("fdAttachment")
If item.Type=1 Then
Set rtitem=item
Forall eo In rtitem.EmbeddedObjects
Set fso=createobject("Scripting.FileSystemObject")
Set wsh=createobject("WScript.Shell")
strFileName=Environ("Temp") & "\" & eo.Name
eo.ExtractFile strFileName
Set varFile=fso.getfile(strFileName)
doc.ReplaceItemValue "DateLastModified", varFile.DateLastModified
doc.ReplaceItemValue "FilePath",strFileName
ret=wsh.run (strFileName,1)
Exit Forall
End Forall
End If
End Sub
Das Problem ist klar. NOTESUIDOCUMENT MUSS GESCHLOSSEN WERDEN UM IM FONTEND WAS ANZUHAENGEN. Nur dadurch geht natürlich das Schliessen was danach ablaufen sollte verloren.
Gruss
Remo