Word 2007 - Content Control in tables

W

wmather

I have a table where I have added Content Control (Drop-down list) in one
cell. I have manually added the same control to each cell in the same column.

If a new row is inserted or added to the table how do I get it to add the
Content Control to the cell n the new row?
 
R

Robert M. Franz [RMF]

Hello wmather
I have a table where I have added Content Control (Drop-down list) in one
cell. I have manually added the same control to each cell in the same column.

If a new row is inserted or added to the table how do I get it to add the
Content Control to the cell n the new row?

I'd wager you can only do this through code (VBA).

An alternative approach might be to save a single-row table with the
desired content as a QuickPart and assign a keyboard shortcut to it.

HTH
Robert
 
G

Graham Mayor

I am not a great lover of Word 2007's content controls, but it is easy
enough to duplicate the last row of a table c/w content using a macro. the
code is based on that at http://www.gmayor.com/word_vba_examples.htm and
assumes that the table is Table1.

Sub AddRow()
Dim oTable As Table
Dim oRng As Range
Dim iRow As Integer
Dim iCol As Integer

With ActiveDocument
Set oTable = .Tables(1) 'Select the appropriate table
iRow = oTable.Rows.Count 'Record the last row number
iCol = oTable.Columns.Count 'Record the last column number
Set oRng = oTable.Rows(iRow).Range 'Add the last row to a range
oRng.Copy 'Copy the row
oRng.Collapse wdCollapseEnd 'collapse the range to its end.
oRng.Select 'the end of the table
Selection.Paste 'Paste the row at the end of the table
oTable.Cell(iRow + 1, 1).Select 'Select the first cell in the new last
row
End With
End Sub

http://www.gmayor.com/installing_macro.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
G

Graham Mayor

Actually the iCol references are from the larger macro and are not required
here - they will not have any effect on the process but can be removed thus

Sub AddRow()
Dim oTable As Table
Dim oRng As Range
Dim iRow As Integer
With ActiveDocument
Set oTable = .Tables(1) 'Select the appropriate table
iRow = oTable.Rows.Count 'Record the last row number
Set oRng = oTable.Rows(iRow).Range 'Add the last row to a range
oRng.Copy 'Copy the row
oRng.Collapse wdCollapseEnd 'collapse the range to its end.
oRng.Select 'the end of the table
Selection.Paste 'Paste the row at the end of the table
oTable.Cell(iRow + 1, 1).Select
End With
End Sub

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
W

wmather

Many thanks Graham. The macro works, but how do I get it to run when I tab
out of the last cell of the table.
 
G

Graham Mayor

The short answer is that you don't. Simply tabbing out of a table will not
run the macro. You could run the macro on exit from a content control, but
unless you are prepared to dig into the mysteries of XML programming you are
not going to get far with that.

My old pal Greg Maxey has some information on his web site about content
control programming that you may find useful -
http://www.google.com/custom?domain...:333333;GFNT:663333;GIMP:663333;FORID:1&hl=en

This takes us back to why I don't like content controls. Legacy form fields
are much simpler to handle - provided you can persuade users to run the
associated macros - and then you could run the macro on exit from a form
field. This is all covered in two examples at
http://www.gmayor.com/word_vba_examples.htm

--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 
R

Robert M. Franz [RMF]

Hello Graham

Graham said:
The short answer is that you don't. Simply tabbing out of a table will not
run the macro. You could run the macro on exit from a content control, but
unless you are prepared to dig into the mysteries of XML programming you are
not going to get far with that.

maybe you could trap the "Next Cell" command, somehow determine whether
you're at the end of a table, and then invoke the macro if needed?

0.2¢
Robert
 
G

Graham Mayor

Doh! Of course! The following will do that for Table1 in the current
document.

Sub NextCell()
Dim oTable As Table
Dim oRng As Range
Dim iRow As Integer
With ActiveDocument
Set oTable = .Tables(1) 'Select the appropriate table
With ActiveDocument.Tables(1)
If Selection.InRange(.Cell(.Rows.Count, .Columns.Count).Range) Then
MsgBox "Last Cell"
iRow = oTable.Rows.Count 'Record the last row number
Set oRng = oTable.Rows(iRow).Range 'Add the last row to a
range
oRng.Copy 'Copy the row
oRng.Collapse wdCollapseEnd 'collapse the range to its end.
oRng.Select 'the end of the table
Selection.Paste 'Paste the row at the end of the table
oTable.Cell(iRow + 1, 1).Select
Else
Selection.MoveRight Unit:=wdCell
End If
End With
End With
End Sub


--
<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
Graham Mayor - Word MVP


<>>< ><<> ><<> <>>< ><<> <>>< <>><<>
 

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