Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
Hi,
I need a macro to select all fields with the same name in 2 ListBox.
For example, if I select 16/11/2008 and 17/11/2008 in the date1 listbox, the macro have to auto-select the same fields for date2.
I tested 2 solutions :
sub Select_dates
ActiveDocument.getField("date2").ToggleSelect "getfieldselections(date1)"
end sub
sub Select_dates2
set fselected = ActiveDocument.Fields("date1").GetSelectedValues
ActiveDocument.Fields("date2").ToggleSelect fselected
end sub
Thanks in advance
This should work for you:
sub NewSelect
list = ActiveDocument.Variables("vDate1").GetContent.String
test = Split(list, ", ")
set fld = ActiveDocument.Fields("date2")
fld.Select test(0)
for i = 1 to UBOUND(test)
fld.ToggleSelect test(i)
next
End Sub
That takes the GetFieldSelections values for date1 using a variable. It then uses the VB command split, to separate that into array elements. For the first item, we use the normal select, which should select only that one. Then we use ToggleSelect for the rest to get the current selection and this one.
I found a solution but it work only for 1 slection, no mutliple selections.
sub Select_dates
ActiveDocument.Fields("date2").Select ActiveDocument.Evaluate("getfieldselections(date1)")
end sub
This should work for you:
sub NewSelect
list = ActiveDocument.Variables("vDate1").GetContent.String
test = Split(list, ", ")
set fld = ActiveDocument.Fields("date2")
fld.Select test(0)
for i = 1 to UBOUND(test)
fld.ToggleSelect test(i)
next
End Sub
That takes the GetFieldSelections values for date1 using a variable. It then uses the VB command split, to separate that into array elements. For the first item, we use the normal select, which should select only that one. Then we use ToggleSelect for the rest to get the current selection and this one.
Thanks for your answer.
You were on the right track with the example you uploaded. It's a one-liner.
ActiveDocument.Fields("date2").SelectValues ActiveDocument.Fields("date1").GetSelectedValues
With V9, I think you can do it without a macro but I'm not sure of the Action specifics. Anyone?
-Rob