duplicate a line in a table

L

LookingGood

Hi,

I am currently creating a document template. In this template has a single
line table with 4 columns, the 1st is a display column whilst 2nd, 3rd & 4th
are input columns (Bookmarked as AccNo, AccName & AccAmt) respectively.

I would like to find a solution to replicate the row and create new
bookmarks as mentioned and concatenated by row number if the user uses a key
(ENTER or INSERT key), on completion from the table, the user then TAB to the
next input field.

My knowledge with macros is limited.

I would appreciate any help in this matter.

Many Thanks
 
J

Jean-Guy Marcil

LookingGood was telling us:
LookingGood nous racontait que :
Hi,

I am currently creating a document template. In this template has a
single line table with 4 columns, the 1st is a display column whilst
2nd, 3rd & 4th are input columns (Bookmarked as AccNo, AccName &
AccAmt) respectively.

I would like to find a solution to replicate the row and create new
bookmarks as mentioned and concatenated by row number if the user
uses a key (ENTER or INSERT key), on completion from the table, the
user then TAB to the next input field.

My knowledge with macros is limited.

I would appreciate any help in this matter.

I am not sure I understood your rquiremnent...
In any case, try this in a regular module in your template:

'_______________________________________
Sub TableInsertRow()
'To intercept the Enter key from the outside
'of the last cell on the right

NextCell

End Sub
'_______________________________________

'_______________________________________
Sub NextCell()

'To intercept the TAB key inside the table
'Will add a new row only if cursor in last cell in last row
'Will not work with table with merged cells

Dim ColNumber As Long
Dim RowNumber As Long
Dim NewRow As Row

With Selection
ColNumber = .Information(wdStartOfRangeColumnNumber)
RowNumber = .Information(wdStartOfRangeRowNumber)

If ColNumber >= 4 Then
If RowNumber < .Tables(1).Rows.Count Then
.Tables(1).Rows(RowNumber + 1).Cells(1).Select
.Collapse
Else
Set NewRow = .Tables(1).Rows.Add
RowNumber = RowNumber + 1
With NewRow
InsertFields .Cells(2).Range, CStr(RowNumber), "AccNo"
InsertFields .Cells(3).Range, CStr(RowNumber), "AccName"
InsertFields .Cells(4).Range, CStr(RowNumber), "AccAmnt"
End With
.Tables(1).Rows(RowNumber).Cells(1).Select
.Collapse
End If
Else
.Rows(1).Cells(ColNumber + 1).Select
.Collapse
End If
End With

End Sub
'_______________________________________

'_______________________________________
Function InsertFields(myCell As Range, RowDigit As String, BookName As
String)

With myCell
.FormFields.Add myCell, wdFieldFormTextInput
.Bookmarks.Add BookName & RowDigit, .FormFields(1).Range
End With

End Function
'_______________________________________

--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
(e-mail address removed)
Word MVP site: http://www.word.mvps.org
 

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