0
votes

Below is the snippet of code I used to extract field value from word file with fields. The fields contain data from a xml document. I need to extract 10 10 data as array(1)=10 and array(2)=10 in below image. The text 10 box 10 may have more than 2 values. I would have to the multiple values in a array. I tried split with delimiter as space, newline. It doesnt split. Then tried

left(x1,(len(x)-1)/2) and right(x1,(len(x)-1)/2)

to extract 2 values. I am new to vba in word and need help in extracting multiple values or splitting based on these boxes which seem to be a table value.

Function calcinput()

x1 = ActiveDocument.SelectContentControlsByTag("TWCAR_Nominal").Item(1).Range.Text

x2 = ActiveDocument.SelectContentControlsByTag("TWCAR_NominalUnit").Item(1).Range.Text

MsgBox x1 + s2

enter image description here

Above image shows the output.

enter image description here

Above image shows data to be extracted

1
Just to be clear, fields and content controls are two entirely different things.Timothy Rylatt

1 Answers

1
votes

Assuming that the content control shown in the screenshot is a Plain Text control with multiple paragraphs enabled, the values will be separated with a line feed character, Chr(11). Splitting the text on this character will give you the array.

Dim quantity As Variant
quantity = Split(ActiveDocument.ContentControls(1).Range.Text, Chr(11))