This forum is closed to new posts and
responses. The content has been migrated to the Digital Solutions Community. Please join us there for new content as well as this content. For customer support, please visit the official HCL customer support channels below:
Finally, I added alot of my own tweaks, including logic in the PostSave event to check to see if MS Word was open, if the document was open in MS Word, if the document edits had been saved in MS Word, and then ensure it is saved/unloaded in Word before re-attaching to the current Notes document. here is my version of the PostSave logic...
Sub ReattachFile( Source As NotesUIDocument )
'
' This subroutine is called from the PostSave event of a Document
' It ensures the edited MS Word document is saved back to the current document before exiting
'
Dim ws As New NotesUIWorkspace
Dim thisDoc As NotesDocument ' This document (backend)
Dim rtitem ' The 'Body" RT item on the document
Dim object ' The original MS Word document object (removed from document)
Dim wordApp ' MS Word application
Dim fileName$ ' The attachment file name (for removal)
Dim fileAttachment$ ' The full path to the file that is to be re-attached
Dim answer ' User's response to system prompt (to save edited MS Word document)
On Error GoTo errorHandler
'
' Haven't edited the attachment - Simply exit
'
If Not( Source.FieldGetText("tmpOpenForEdit")="1" ) Then Exit Sub
'
' Retrieve attachment object from 'Body' item.
' If not there, fail over to checking the document
'
Set thisDoc=Source.Document
Set rtitem = thisDoc.GetFirstItem( "Body" )
If Not IsArray( rtitem.EmbeddedObjects ) Then Exit Sub
ForAll embObj In rtitem.EmbeddedObjects
fileName$ = embObj.Name
Exit ForAll
End ForAll
If ( rtitem.Type = RICHTEXT ) Then
Set object = rtitem.GetEmbeddedObject( fileName$ )
If object Is Nothing Then Set object = thisDoc.GetAttachment( fileName$ )
End If
If Not( object Is Nothing ) Then Call object.Remove
'
' Update the RT field and save the document
'
Call rtitem.Update
Call thisDoc.Save(True, True)
'
' Ensure the MS Word document is saved (if it is still open)
'
fileAttachment$ = Source.FieldGetText( "tmpFileLocation" )
On Error Resume Next
Set wordApp = GetObject( ,"Word.Application" )
On Error GoTo errorHandler
If Err() = 0 Then ' Word is open
ForAll wordDoc In wordApp.Documents
If StrCompare( wordDoc.FullName, fileAttachment$, 5 ) = 0 Then ' The detached file is open in MSWord
answer = 0
If Not( wordDoc.Saved ) Then ' Edits have not been saved in MS Word
answer = ws.Prompt( PROMPT_YESNO, "Save Document", "Would you like to save the changes you made to the MS Word document?" )
End If
If answer = 1 Then
Call wordDoc.Close( True )
Else
Call wordDoc.Close( False )
End If
End If
End ForAll
End If
'
' Re-attach edited MSWord document to this document,
' then remove the Word document from the disk
'
Set object = rtitem.EmbedObject( EMBED_ATTACHMENT, "", fileAttachment$ )
Call rtitem.Update
Kill fileAttachment$
'
' Reset trigger fields and save the document
'
thisDoc.tmpOpenForEdit = "0"
thisDoc.tmpFileLocation = ""
Call thisDoc.Save( True, True )
Exit Sub
errorHandler:
If Err() = 9999 Then
MsgBox Error(), 0+16, "Save Document"
Else
MsgBox "Error " & Err() & " at line " & Erl() & " of 'ReattachFile': " & Error(), 0+16, "Save Document"
End If
Exit Sub
End Sub
Feedback response number WEBB8R3UHN created by ~Wei Asatoopulakol on 02/01/2012