Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I've a variable vFields=A,B,C. I want to create a table box with varaible contents. A,B ,C are the fields in my script. I tried the below code to achive this but it is not working. Here vCatchCount holds the count of vFields(i,.e vCatchCount=substringcount($(vFields,',') it returns 2.
sub AddToTableBox
set val=ActiveDocument.Variables("vCatchCount")
set vFields=ActiveDocument.Variables("vFields")
set TB = ActiveDocument.Sheets("Main").CreateTableBox
for i=0 to val.GetContent.String
TB.AddField vFields.Item(i).Text
next
end sub
- The above code works when we tried with fields data.
For Eg:
sub AddToTableBox
set val=ActiveDocument.Fields("F1").GetPossibleValues
set TB = ActiveDocument.Sheets("Main").CreateTableBox
for i=0 to val.Count-1
'msgbox(val.Item(i).Text)
TB.AddField val.Item(i).Text
next
end sub
Hi Jagan,
As far as I know you cannot treat a variable as an array, so you cannot use the code 'vFields.Item(i).Text'.
Try doing this:
1. Before the for loop, create an array:
ArrFields = split(vFields.GetContent.String, ",")
2. Replace the code inside the for loop:
TB.AddField ArrFields(i)
This code should work but I haven't tested it, so you may have to do some adjustments...
Hope this helps you. Regards,
Fernando
Hi Jagan,
As far as I know you cannot treat a variable as an array, so you cannot use the code 'vFields.Item(i).Text'.
Try doing this:
1. Before the for loop, create an array:
ArrFields = split(vFields.GetContent.String, ",")
2. Replace the code inside the for loop:
TB.AddField ArrFields(i)
This code should work but I haven't tested it, so you may have to do some adjustments...
Hope this helps you. Regards,
Fernando
Fernando,
Thanks for your help. But it is not working when i give more than 3 contents in variable.
For eg:
vFields=A,B,C,D,E,F,G,H
sub SeleccionarCampos
set val=ActiveDocument.Variables("vCatchCount")
set vBookMark=ActiveDocument.Variables("vFields")
set TB = ActiveDocument.Sheets("Main").CreateTableBox
ArrFields = split(vFields.GetContent.String, ",")
for i=0 to val.GetContent.String
' msgbox(ArrFields(i))
TB.AddField ArrFields(i)
next
end sub
- But when i comment the createtablebox code and addfield code. Then it displays all contents through messagebox. But not able to add filds.
Hi,
See if the attached sample can help you.
Cheers.
BlackRockS / Fernando,
Actually the fernando code is working good. But i forgot to add other fields in script(i.e D,E,F...).
BlackRockS your code is also good.
Can anyone of you help me on this Thread
Thanks a lot...
Fernando/BlacRockS,
Can you solve this thread plz.. it is related to above post.