Macro for pasting a block of table below current block

R

Rufer

Hello, I am trying to develop an agenda template. Every agenda item on the
template has 6 table cells associated with it. I want the template to open
with only one blank agenda item (the 6 cells) on it.

When the user needs to add another agenda item below that, I want them to
tap a MacroButton and paste an empty version of the cells below.

What I want to know most significantly is how I store the blank cells and
refer to them in the macro.

I hope this makes sense. I'm new at this. If anyone REALLY wants to help
me I can email you the file I'm working with to hopefully make it more clear.
 
D

David Horowitz

Rufer,
What do the desired blank cells look like - for example, is it just a row of
6 blank cells? Is it two rows of three? 6 cells vertically stacked?
Do they have pre-filled data in them, or are they really blank?
If they're 6 in a row and really blank, can't you just have the user press
Tab on the very last cell to insert a new row at the bottom?
If it's something more complex than that, some fairly simple macro code
should be able to do what you want. Of course, "simple" depends on where
you're starting from - do you have any VBA experience?
 
R

Rufer

Hi David,
Thanks for replying. There are some text form and dropdown list fields in
these cells.

I have very little vba experience. I can record a macro through word and
apply the MacroButton to it. What I don't know how to do is to have the
Macro recognize the formatting and content of the otherwise empty cells.

I certainly suspect this is an easy task for anyone with slightly more
experience than me.
 
D

Doug Robbins - Word MVP on news.microsoft.com

You should be able to modify the following macro to do what you want:

Sub AddRow()
Dim rownum As Integer, i As Integer
With ActiveDocument
.Unprotect
.Tables(1).Rows.Add
rownum = .Tables(1).Rows.Count
For i = 1 To 3
.FormFields.Add Range:=.Tables(1).Cell(rownum, i).Range,
Type:=wdFieldFormTextInput
Next i
.FormFields.Add Range:=.Tables(1).Cell(rownum, 4).Range,
Type:=wdFieldFormDropDown
With .Tables(1).Cell(rownum, 4).Range.FormFields(1).DropDown.ListEntries
.Add "Item1"
.Add "Item2"
.Add "Item3"
.Add "Item4"
.Add "Item5"
End With
.FormFields.Add Range:=.Tables(1).Cell(rownum, 5).Range,
Type:=wdFieldFormDropDown
With .Tables(1).Cell(rownum, 5).Range.FormFields(1).DropDown.ListEntries
.Add "ItemA"
.Add "ItemB"
.Add "ItemC"
.Add "ItemD"
.Add "ItemE"
End With
.Tables(1).Cell(rownum, 5).Range.FormFields(1).ExitMacro = "AddRow"
.Tables(1).Cell(rownum, 1).Range.FormFields(1).Select
.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End With
End Sub

--
Hope this helps.

Please reply to the newsgroup unless you wish to avail yourself of my
services on a paid consulting basis.

Doug Robbins - Word MVP, originally posted via msnews.microsoft.com
 

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