VBA - Insert Row with Form Fields at End of Table

  • Thread starter spunkymuffmonkey
  • Start date
S

spunkymuffmonkey

Hi,

I am currently creating an automated form in which there's a table. In this
table users record various details regarding risks. The table contains 10
rows and seven columns with form fields in each cell (apart from the heading
row), each risk is recorded across a row.

My problem is that the number of rows a user might complete on this form
could be over 10, users mostly won't go over ten, but when they do I want the
form to automatically add a row to the end of the table with the form fields
copied in to the new row.

Using my primative VBA knowledge I have managed to create the following but
cannot work out how to paste my selection at the end of the table.

Sub AddRow()

ActiveDocument.Unprotect

ActiveDocument.Tables(1).Rows(2).Select

Selection.Copy

Selection.Paste

ActiveDocument.Protect wdAllowOnlyFormFields

End Sub

I have seen other posts within the forum

(http://www.microsoft.com/communitie...7e03f1-950d-4edb-8d9b-0d1670d54d42&sloc=en-us)

but cannot get the example to work as the code tells me there is a syntax
error when I run it and some of the code appears in red when I paste it into
the code window.

Please help!
 
J

Jean-Guy Marcil

:

I have seen other posts within the forum

(http://www.microsoft.com/communitie...7e03f1-950d-4edb-8d9b-0d1670d54d42&sloc=en-us)

but cannot get the example to work as the code tells me there is a syntax
error when I run it and some of the code appears in red when I paste it into
the code window.

If the code appears in red it simply means that the compiler cannot make
sense of those lines.

If you are using code you got on the web, the usual reason is that longer
lines have been split in two (or more) shorter lines when they were posted by
a browser.

Place the cursor at the end of a red line that is followed by another red
line. Hit "Delete" until the two lnes are one, making sure not to delete any
actual characters.

You may have to adjust Quotes if there were any.

If you have a single red line, it maybe that the next line happens to be a
line the compiler understands as is, but it should probaboy be brought back
with the preceding line.

If you are not sure, post the red lines here, together with the few lines
that precede and follow.
If the whole code is fairly short, you can post the whole thing specifying
which lines are red.
 

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