Read MS Word using LotusScript

We have a Word Form with defined fields that is sent to a customer & returned filled in. We would like to be able to access the Word doc from within Notes (LotusScript) and update database fields. I’ve found how to open the Word doc as a Word application object but can’t seem to find any documentation anywhere that defines the objects/properties/methods of a Word doc. I’ve found examples how to create/write to a Word doc, but not how to access fields (bookmarks) from one. Any help would be greatly appreciated.

Subject: Read MS Word using LotusScript

Try this link or search for MS WORD Document Object Model

Subject: Getting values fromFields, FormFields and Bookmarks

Hi

Here is a quick example of an agent that checks if a word document is protected and then looks for a Field(bookmark), a customDocumentProperty, and a FormField

Hope this helps

Tim

Dim ActiveDocument As Variant 'Global

Sub Initialize

Dim fileName As String

fileName = "h:\myWordDoc.doc"

Set activeDocument = GetObject(fileName, "Word.Document")

activeDocument.Application.Visible=True



'ensure the document is unprotected (if you can). Working with protected documents can be alot of fun

If activeDocument.ProtectionType <> -1 Then

	Msgbox ("This document is protected, please unprotect and try again")

end

End If



'Check for fields (defined by bookmarks)

If activeDocument.Bookmarks.Exists("MyField") = True Then

	activeDocument.Bookmarks("MyField").Select

	fval= activeDocument.ActiveWindow.Selection.Range.Text

Else

	Msgbox ("Could not find bookmark for MyField")

End If



'Check for custom props

If CustomPropertyExists("MyProperty") Then

	cVal = activeDocument.CustomDocumentProperties("MyProperty").Value

Else

	Msgbox ("Cannot find property myProperty")

End If

'Check for FromFields

If FormFieldExists("myField") Then

	mVal = activeDocument.FormFields("myField").Result

Else

	Msgbox ("Cannot find Form Field myField")

End If

End Sub

Function CustomPropertyExists(CustomPropertyName As String) As Boolean

CustomPropertyExists=False

Forall propCustom In ActiveDocument.CustomDocumentProperties

	If propCustom.Name = CustomPropertyName Then

		CustomPropertyExists=True

		Exit Function

	End If

End Forall

End Function

Function FormFieldExists(FormFieldName As String) As Boolean

FormFieldExists=False

Forall aField In ActiveDocument.FormFields

	If aField.Name = FormFieldName Then

		FormFieldExists=True

		Exit Function

	End If

End Forall

End Function

Subject: Getting values from Fields, FormFields and Custom Properties

This might be better for getting the value out of a field

If activeDocument.Bookmarks.Exists(“MyField”) = True Then

activeDocument.Bookmarks(“MyField”).Select

fval= activeDocument.ActiveWindow.Selection.Range.Fields(1).Result

Else

Msgbox (“Could not find bookmark for MyField”)

End If

Subject: Read MS Word using LotusScript

You can record a Word macro and then examine the code there. With small changes the macro code can be used in LotusScript.

I have some example of using Excel object from LotusScript, but not Word: Botstation - Code Vault