Word table and formfields

V

VBA Neophyte

I have a table with rows containing some plain text and some formfields,
including a Yes checkbox. I want to copy selected cells of selected rows of
the table either to the end of the existing doc or to another doc, but only
the rows where the Yes checkbox is checked. Any suggestions?

Example: In this table, some rows (e.g. a high-level header) do not have the
Checkbox row; but if cell 3 of the row contains the Checkbox, then: cell 2 is
plain text, cell 3 is Yes CheckBox formfield, cell 4 is plain text, cell 5 is
an TextInput formfield. If the Yes CheckBox in cell 3 = Yes, I want to copy
cells 2. 4 and 5 to a new table at the end of the document or into a new
table in a new separate document.
 
Z

zkid

There are a couple of ways to go about this. The easiest is to name the
checkboxes (do this through the bookmark field within the form field). Then,
use this code to check it:

If ActiveDocument.FormFields("BookmarkNameHere").CheckBox.Value = True Then
'code here to copy the desired cells. Sorry, but it is unclear how you
are determining which cells to copy
End if
 
V

VBA Neophyte

Thanks for your response. Here's what I want to do:

If the CheckBox value in cell 3 = true, I want to copy cells 2. 4 and 5 to
a new table at the end of the document or into a new table in a new separate
document. Cells 2 and 4 are plain text in the table; cell 5 is a formfield.

I don't know how to do a copy statement for a range with some plain text
cells and a formfield cell.

Also, this is pretty repetitive, so I was looking for something that would
just step through the table without having to specifically refer to formfield
Bookmark name, e.g. using a counter index to do the following

Row(i) : if cell 3 contains a checkbox with value = Yes, copy contents of
cells 2, 4 and 5 to next line in new table.
 
Z

zkid

Is the document protected for the formfields, or are you using ActiveX
controls?

Is the table consistent (e.g., same number of rows and columns without any
cells merged or split in between)?
 
V

VBA Neophyte

The document is protected for the formfields.

The table, unfortunately, is not consistent. It has some embedded merged
cells and some split cells. I was wondering about handling these as separate
sections, then I could at least have a few different macros based on
format/section range. If this makes sense.
 
Z

zkid

Okay, I was concerned about those items. We have three issues here. The
fact that the doc is protected means you will need to unprotect it in order
to add the new information to the end and then reprotect it. Definitely you
would be better off creating an unprotected section in which to copy the data.

Second, if the table columns/rows are inconsistent, it is more difficult to
step through the table and determine and copy the correct cell's data.

Third, I think you stated that some of the data to be copied is from
straight text and some of it resides in a form field. Again, that means
unprotecting the doc and reprotecting it in order to copy straight text from
a cell. If they are all formfields, then no unprotecting is necessary.

If there wasn't any straight text, naming the formfields would be the way to
go. But, it appears you don't have that option here.

I need to think about this over the weekend when I have more time. In the
meantime, I suggest you repost this in the VBA General Question community, as
this question is much more complex than the beginning VBA community can
handle. For the subject line, title it something like Stepping through
protected table cells.
 

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