Update Word to Notes or Notes to Word Using a Word Template as the Guide

Author: Tripp W Black

Created: 09/21/2000 at 08:49 AM

 

Category:
Notes Developer Tips
Agents, LotusScript

Attached is a sample Notes Application that creates a MS Word document based
on a word template (also attached) and passes information from notes to the
Word document. There is also code in the agent (currently commented) to
retrieve information from the Word Document and update the Notes document.
<<OLETest.dot>> <<oletest.nsf>>

OLETest.dotoletest.nsf

Here is the lotusscript code for the agent:
The long awaited code....

Below is code that you can use in a LotusScript agent to create a Microsoft Word document. The code also populates data in Word field from Notes Document fields.

Sub Initialize
Dim workspace As New NotesUIWorkspace
Dim uidoc As NotesUIDocument
Dim curdoc As NotesDocument
Set uidoc = workspace.CurrentDocument
Set curdoc = uidoc.document
' you can also get an open instance of Word if one exists
Set ole_word = createobject("word.application")
' you can have Word do the processing in the background
' by setting the property to FALSE.
ole_word.visible = True
' This is the name of the Word template that the be used
' It must be created as a form with fields to accept the data
ole_word.documents.add ("C:\OLETEST.dot")
' The FormField names are the names that you assigned to
' to the word document when you created the template
ole_word.ActiveDocument.FormFields("Field1").Result = curdoc.Field1(0)
ole_word.ActiveDocument.FormFields("Field2").Result = curdoc.Field2(0)
ole_word.ActiveDocument.FormFields("Field3").Result = Left(curdoc.Field3(0),1)
ole_word.ActiveDocument.SaveAs ("C:\test.doc")
' ole_word.ActiveDocument.Print
' some features cannot be accessed from the Notes side
' If you need additional functionality, you can create a Word
' Macro to perform the remaining necessary processing.
ole_word.Run ("MoveToEnd")
' ole_word.ActiveDocument.Close
End Sub

previous page