advise on repeative code item

N

Nick Calladine

Hi

I currently have a table in which i am populated each added row with a
dropdown box.
I have tried to record the following through the macro record and need two
point answering.

One is there a better coding way of doing this correctly.

Secondly i cant seem to get away of adding to each row cause of syntax of
selecting the last drop down thats it has added
I understand this take the index of the formfield
So i need to work it to so it either finds the maximum index of the
formfield and then minus 1 to get the last added formfield or a better in my
case a general piece which at time of adding select the formfield i just
added.

The formfield is exactly the same in every row.

Please can some one point me in the right direction and shed some light

Many thanks

Code Below -->


.FormFields.Add Range:=Selection.Range, Type:=wdFieldFormDropDown
Selection.PreviousField.Select
With Selection.FormFields(1)
.Name = "CIS"
.Enabled = True
.OwnHelp = False
.HelpText = ""
.OwnStatus = False
.StatusText = ""
End With

Selection.FormFields("CIS").DropDown.ListEntries.Clear
Selection.FormFields("CIS").DropDown.ListEntries.Add Name:="CIS 4"
Selection.FormFields("CIS").DropDown.ListEntries.Add Name:="CIS 6"
Selection.FormFields("CIS").DropDown.ListEntries.Add Name:="VAT"
Selection.FormFields("CIS").DropDown.ListEntries.Add Name:="None"
 
G

Greg

If I understand correctly, you are looking for code to add a row to the
end of the selected table and then put a populated dropdown field in
that new row. Something like this may help:

Sub Test()
Dim i As Long
Dim oRng As Range
Dim fFld As FormField

Selection.Tables(1).Rows.Add
i = Selection.Tables(1).Rows.Count
Set oRng = Selection.Tables(1).Cell(i, 1).Range
Set fFld = oRng.FormFields.Add(Range:=oRng, Type:=wdFieldFormDropDown)
With fFld
.Name = "CIS" & i
.Enabled = True
.OwnHelp = False
.HelpText = ""
.OwnStatus = False
.StatusText = ""
With .DropDown.ListEntries
.Add Name:="CIS 4"
.Add Name:="CIS 6"
.Add Name:="VAT"
.Add Name:="None"
End With
End With
End Sub
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top