Can I use a Word Document Table of Contents to create Notes Documents

If I have a Word document that has an existing Table of Contents, can I create individual Notes Documents that would be associated with each of the Table of Content entries?

Thx in advance if anyone has done anything like that?

Hello @Paul Ryan

Regarding mentioned requirement, there is possibility of mail merge excel to notes.

Kindly refer more information on this from open ntf for using mail merge using excel.

https://www.openntf.org/main.nsf/project.xsp?r=project/MailMerge%20Excel%20to%20Notes

Requesting you to kindly check above information from reference purpose and check if it helps with your requirement.

Regards,

Pramod

Thx for yours, Pramod, but the source is a Word doc, not an Excel spreadsheet. The source Word doc is provided to our Clients by the United States government and is many hundreds of pages of regulations and that can't be changed.

Cheers

Hi Paul,

Do you want to perform the import word document content into Notes Document?

If yes does the word document contains bookmark field?

Last time we have created the custom code for Exporting data of Notes Document to Microsoft Word template file with in build bookmarks in it

Below code is for Exporting Notes Document to Word document.

Same context can be used for Importing Word document into Notes Documents with the help of your internal developer if any

************Code starts here*********

On Error Goto Handle
' Initialize variables
Dim session As NotesSession
Dim ws As New NotesUIWorkspace

Dim curdb As NotesDatabase
Dim doc As NotesDocument
Dim uidoc As notesuidocument
Dim strTemplate As String

'Get session and database
Set session = New NotesSession
Set curdb = session.CurrentDatabase
Set uidoc=ws.CurrentDocument
Set doc = uidoc.Document

'file path of word template file. Please use the extension as .docx.
'dotx extension will result in error

strTemplate ="C:\WordTemp\Memo.docx"

'Create object of word doc and template file
Set wordObj = CreateObject("Word.Application")
Call wordObj.Documents.Open(strTemplate)
Set wordDoc = wordObj.ActiveDocument

'Add values from doc in Bookmark of word doc
With wordDoc
.Bookmarks("ToField").Range.Text= doc.ToTX(0)
.Bookmarks("FromField").Range.Text= doc.FromTX(0)
.Bookmarks("DateField").Range.Text= doc.DateTX(0)
.Bookmarks("RefNo").Range.Text= doc.RefTX(0)
.Bookmarks("SubjectField").Range.Text= doc.SubjectTX(0)
End With
' save word
wordObj.ActiveDocument.Save

wordObj.Visible = True
wordObj.Activate

' Close word
wordObj.application.quit
Set wordObj=Nothing
Msgbox "Document Exported successfully in Word "
Exit Sub
Handle :
Msgbox "Error is " & Error() & " On Line " & Cstr(Erl())

************Code Ends here*********

Kind Regards,

Pravin.

Thx for your suggestion and sample code, Pravin.

Our ultimate objective is to create a drop down list on a Notes Doc, using the Bookmarks in the Word document as the source for that list.

We'll give your appoprach a try and see if it works for this requirement.

thx again.

Hi Pravin, if you have some time to discuss, plse contact me at pryan@paragoncda.com

Hi Paul,

This is the LotusScript code and a sample Word document with a Table of Contents attached.
Kindly find the attachment.
Also adding the VBA reference for the Table of Contents
LotusScript Code:
Sub Initialize
On Error Goto checkerror

Dim wordApp As Variant
Dim wordDoc As Variant
Dim docPath As String
Dim tocRange As Variant
Dim docRange As Variant
Dim tocText As String

' Set the path to the Word document
docPath = "C:\TEST\document.docx"
' Create a new instance of the Word application
Set wordApp = CreateObject("Word.Application")

' Set the visibility of the Word application
wordApp.Visible = False

' Open the Word document
Set wordDoc = wordApp.Documents.Open(docPath)
Set docRange = wordDoc.Range(0, 0)
' Get the range of the table of contents
If wordDoc.TablesOfContents.Count > 0 Then
Msgbox "Number of TablesOfContents: " & wordDoc.TablesOfContents.Count
Else
Msgbox "Document doesn't contain a table of contents"
Exit Sub
End If

Set tocRange = wordDoc.TablesOfContents(1).Range

' Read the text of the table of contents
tocText = tocRange.Text

' Display the text of the table of contents
Msgbox tocText

' Close the Word document
wordDoc.Close

' Quit the Word application
wordApp.Quit

' Release the objects
Set tocRange = Nothing
Set wordDoc = Nothing
Set wordApp = Nothing

'Create the Notes Document
Dim session As New NotesSession
Dim db As NotesDatabase
Dim doc As NotesDocument

Set db = session.CurrentDatabase
Set doc = db.CreateDocument

doc.Form = "tocDoc"
doc.tocFieldName = Left(tocText, Len(tocText) - Len(Right(tocText, 3)))
doc.tocFieldPageNum = Fulltrim(Right(tocText, 3))
Call doc.Save(True,False)

checkerror:
If Erl > 0 Then
Print "Error on line# " & Erl & " >> " & Error
wordApp.Quit
End If
End Sub
Please let us know the concern if any.
document.docx