I have been using some code from the Microsoft Office Library template. From the “OLERoutines” script library, I have been using the “GetOrCreateOLEObject” routine. Basically I have stripped it down to:
This works great - it opens Word and inside of the Notes client.
However, I want to copy field values from the Notes Document to the Word Document, using a Word Document that I have created with Merge fields on it. In this “GetOrCreateOLEObject” script library, I see the code:
'Create Word document using Template (or file)…
Set oleobject = doc.CreateObject(“OLEObject”,note.~$OLEObjProgID(0),“”)
However, it uses an actual file to create using a template (which I assume I could use my Word document/file as the templateName variable). I want to use my Word document with the Merge fields when the button/action is used from the Notes Document, but not have to retrieve it from a folder on my/server hard drive. I want to store it in the Notes document and use it from there.
I was thinking this:
Create object using my Word Document with Merge fields
Copy fields over
Make Word Document visible
Is there a good routine in copying fields from a Notes Document to a Word Document?
Is there a way to use the Word Document I created with the Merge fields by storing it in the Notes Document and not on a hard drive?
Any good sites with OLE samples (especially for Notes/Word integration)?
I have done a little work around to use my own Word document as the template: I copy and save it to the C:\ drive, then pick it up in my script.
The script I am using works, however, I want to have Word open in Notes, so the user is always in Notes.
My script is attached (a little messy) and I would like to know what am I missing to have it open Word in Notes.
Thanks!
Sub CreateInWord
On Error Goto ProcessError
Dim NotesField As String
Dim WordField As String
Dim LetterFields As Variant
Dim wordApp As Variant
Dim wordDoc As Variant
Dim NotesFieldValue As Variant
Dim TildePosition As Integer
'Set wordDoc = doc.CreateObject("OLEObject",note.~$OLEObjProgID(0),"")
'Call wordDoc.Range().InsertFile(LetterFilePath)
'Create Word Object. Start the word program
Set wordApp = CreateObject("Word.Application")
wordApp.visible = False
'Create word document form the template
Set wordDoc = wordApp.Documents.Add(LetterFilePath)
'Let's get the Field Mapping...
LetterFields = docCodes.Subkeywords
Forall Fields In LetterFields
'Lets' parse the fields...
TildePosition = Instr(1, Fields, "~~")
If TildePosition = 0 Then
Else
'Let's break TheString into two parts to begin processing...
NotesField = Left$(Fields, (TildePosition-1))
WordField = Right$(Fields, (Len(Fields) - TildePosition-1))
'Now we have the field names,
'Let's copy over the fields...
NotesFieldValue = note.GetItemValue(NotesField)
wordDoc.FormFields(WordField).Result = NotesFieldValue(0)
End If
End Forall
wordApp.visible = True
Exit Sub
ProcessError:
Continue = False
'wordDoc.Close
wordApp.Quit
Message = "Error (" & Cstr(Err) & "): " & Error$ & " on line " & Cstr(Erl) & " in in LetterOLERoutines: CreateInWord."
Call ErrorDisplay(Message, NotesOrWeb(0))
Exit Sub