Pages: 1
Author Topic: Multiple Entry Tags Add Text  (Read 110 times)
Boyd White

Posts: 2

« on: March 11, 2019, 03:47:13 PM »

I have been R&D'ing how to select multiple entry tags in a column then add a &tab; at the front of the content of each of those entry tags.

This has proved more difficult that I would have thought. How do you, in a macro, loop through the multiple Entry Tags selected and add text?

Thanks in advance!
Boyd White

Posts: 2

« Reply #1 on: March 13, 2019, 07:11:23 AM »

This will show me every entry's content in a column:

Set ttable = ActiveDocument.documentElement   
Set tgrouplist = ttable.getelementsbytagname("tgroup")
Set tbodylist=tgrouplist.item(0).getelementsbytagname("tbody")
Set tentrylist=tbodylist.item(0).getelementsbytagname("entry")

For j = 0 To tentrylist.length-1
   msgbox("contents = " + contents)

But I don't need every entry's value...I need only those entry tags that have been selected in the column. I have to add a &tab; at the front of their content.

Anybody have some clues. This has turned out to be harder that I would have expected. In R&Ding I have not even been able to get the Range Start and Range End to maybe exclude those outside during the loop of "j" above.

Thanks in advance.
Derek Read
Program Manager (XMetaL)

Posts: 2601

« Reply #2 on: March 14, 2019, 03:10:34 PM »

Because users interact with tables in a unique way when compared to standard elements in a document (what the user is seeing doesn't line up 1:1 with the XML so things get complicated) you need to use special (new and as yet undocumented) APIs to get a user's selection when it might consist of selected cells in a table.

Here's something that does what I think your example code is trying to do.
You can paste these into a document to see them run:

Code: (VBScript)
'XMetaL Script Language VBScript:
If Selection.IsMultiCellSelection Then
    Set c = Selection.Cells
For j = 0 to c.length
Application.Alert("content: " & Selection.Text)
End If

Code: (JScript)
//XMetaL Script Language JScript:
if(Selection.IsMultiCellSelection) {
    var c = Selection.Cells;
for(j=0; j<c.length; j++) {
Application.Alert("content: " + Selection.Text);
« Last Edit: March 14, 2019, 03:14:18 PM by Derek Read » Logged
Pages: 1
Jump to: