0
votes

I have an agent that uses the StoryRanges object in MS Word OLE to do a find and replace in a word template with fields in Lotus Notes. An example of the code I am using is here:

If (FoundWordDoc = True) then
 ForAll rngStory In objWordDoc.StoryRanges  
 rngStory.Find.Execute "{{createddate}}", False, True,,,,, 1,,Format$(doc.DocDate(0), "d mmmm yyyy"), 2,,,,
End Forall

The template is now more complex than it used to be. I need to populate a table based on some documents in Lotus Notes. The number of rows is dependant on the number of records in Notes. One way to do this is to tab my way through the table so that Word manages the additional rows - however I do not want to insert an actual tab. I was thinking I would loop through an array to allow this data to be entered.

I have used OLE To create a Word document from scratch however I am not sure how to go from doing a find an replace to actually inserting or adding to a table in the word document.

Another solution I have thought of, but am unsure how to do it, is to locate a section in the document to create an anchor point and then add the table from there?

1
Hi, I encountered a solution where the table was created in excel and then inserted into word. - umeli

1 Answers

0
votes

The most efficient way to create a table with multiple rows (IOW from multiple records) is to first concatenate the data into character-delimited format as a String. For example

item1;item2;item3
item1;item2;item3
item1;item2;item3

Where each record is separated by ANSI 13 (this is a must, the item-separator can be anything you want).

Assign this to a Word.Range

RngStory.Text = strData

Then convert this to a table using the built-in method:

ObjTable = RngStory.ConvertToTable(";")

The method takes a number of optional arguments. You'll want to read up on it to decide which ones you need.

If you then need to format or work with the resulting table in any way use ObjTable (which, depending on your programming language you may need to declare, first - I'm not familiar with Lotusscript so I can't include that.)