PDA

View Full Version : Indexing Repeating Content Control



mrprex
01-03-2017, 04:16 PM
Hi! I am new here!

I am a beginner in vba and need some assistance.

On the table below, we have a content control that can repeat. on the example below see column "CRR".

We are extracting the value of the repeating CRR using the code below. It works however the result is not in order. on this case the extracted value is 2,3,1. how do we make it in order to show 1,2,3?
Sub TESTRUN()
Dim S As Integer
Dim E As Integer
Dim M As String
E = ActiveDocument.SelectContentControlsByTag("CRR").Count
For S = 1 To E

M = ActiveDocument.SelectContentControlsByTag("CRR").Item(S).Range.Text & " " + "; " + M

Next S

End Sub




#

Facility

Note #

Borrower

*

CRR

NRR

C Acc

N Acc

Interest Accrual

Term / Amo.

Approx. Mthly Pmt

Maturity

Commit.
($000’s)

Out.
($000’s)



-

Facility

Note

Borrower

^

1

-

-

-

Accrual

T/A

Pmt

Date

Commit

Out



-

Facility

Note

Borrower

^

2

-

-

-

Accrual

T/A

Pmt

Date

Commit

Out



-

Facility

Note

Borrower

^

3

-

-

-

Accrual

T/A

Pmt

Date

Commit

Out

SamT
01-03-2017, 05:52 PM
M = M + Active. . . .etc

mrprex
01-03-2017, 05:55 PM
M = M + Active. . . .etc

thank you. I will try that

mrprex
01-03-2017, 06:01 PM
It didn't work. I added a new row (4th row) and the 4th content control was placed 3rd instead on the 4th place

SamT
01-03-2017, 09:40 PM
I don't understand what you are trying to tell us.

gmayor
01-03-2017, 10:53 PM
You can achieve what you require by referencing to the table (I have assumed table 1) rows rather than to the content controls e.g.


Sub TESTRUN()
Dim S As Integer
Dim E As Integer
Dim M As String
Dim oRow As Range
Dim oCC As ContentControl
E = ActiveDocument.SelectContentControlsByTag("CRR").Count
For S = 2 To ActiveDocument.Tables(1).Rows.Count
Set oRow = ActiveDocument.Tables(1).Rows(S).Range
For Each oCC In oRow.ContentControls
If oCC.Tag = "CRR" Then
M = M & oCC.Range.Text
If S < ActiveDocument.Tables(1).Rows.Count Then
M = M & " " + "; "
End If
Exit For
End If
Next oCC
Next S
MsgBox M
End Sub