P
Paul Denton
Cheryl
using bookmarks in protected documents doesnt always work
i have found so when I want rows adding to tables i
usually use the table row count as follows as long as the
last row in the table is the same format as the one you
wish to add.
First of all you need to know the table no for the row to
be added you can find this by just counting the tables in
the document remember if you have section braks in your
tables they look like one table but it actaully splits
them into 2 or use the following to locate the row and
table you want
Sub findtableno()
Dim z
Dim a
'count number of tables in document
z = ActiveDocument.Tables.Count
For a = 1 To z
ActiveDocument.Tables(a).cell(1, 1).Select
msgbox"table " & a & " selected
end sub
Once you know the table no where you want add the rows
use the following
Sub enternewrow()
'
Dim y
Dim a, b, c
ActiveDocument.Unprotect
'count the number of rows in the table where 1 is
replaced by the table no.
y = ActiveDocument.Tables(1).Rows.Count
'select the last row 1st column
ActiveDocument.Tables(1).Cell(y, 1).Select
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.InsertRows 1
Selection.Collapse Direction:=wdCollapseStart
'redifine y to increase by 1 for the new row
which has been added
y = y + 1
' then select the last row, and column you want
to put text or field in
'change the 1 to which ever column you want
ActiveDocument.Tables(1).Cell(y, 1).Range.Text
= "hello"
'when using form fields always ensure noreset is
set to false
'in the protect statement otherwise when you
unprotect andadd you new
'rows and then protect the document anything
entered into any
'formfield will be reset to blank and the user
wont be happy
ActiveDocument.Protect Password:="",
NoReset:=False, Type:= _
wdAllowOnlyFormFields
End Sub
if you still want to use the autotext method then its the
same principle as follows.
Sub enternewrow()
'
Dim y
Dim a, b, c
ActiveDocument.Unprotect
'count the number of rows in the table where 1 is
replaced by the table no.
y = ActiveDocument.Tables(1).Rows.Count
'select the last row 1st column
ActiveDocument.Tables(1).Cell(y, 1).Select
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.InsertRows 1
'when using autotext ensure you always save the
autotext entry
'in the template of the document and not the
normal.dot that way the
'autotext goes with the template and is always
available.
'Also always ensure you include:- RichText:=True
this
'means any formatted text remains as it was when
placed in the auto text
ActiveDocument.AttachedTemplate.AutoTextEntries
("singlewitness").Insert Where _
:=Selection.Range, RichText:=True 'Insert
autotext entry
'when using form fields always ensure noreset is
set to false
'in the protect statement otherwise when you
unprotect andadd you new
'rows and then protect the document anything
entered into any
'formfield will be reset to blank and the user
wont be happy
ActiveDocument.Protect Password:="",
NoReset:=False, Type:= _
wdAllowOnlyFormFields
End Sub
then when you have this working just set varibles in
relation to which checkbox is selected so the insert new
row loops how evermany times you want.
If you get stuck repost.
paul
using bookmarks in protected documents doesnt always work
i have found so when I want rows adding to tables i
usually use the table row count as follows as long as the
last row in the table is the same format as the one you
wish to add.
First of all you need to know the table no for the row to
be added you can find this by just counting the tables in
the document remember if you have section braks in your
tables they look like one table but it actaully splits
them into 2 or use the following to locate the row and
table you want
Sub findtableno()
Dim z
Dim a
'count number of tables in document
z = ActiveDocument.Tables.Count
For a = 1 To z
ActiveDocument.Tables(a).cell(1, 1).Select
msgbox"table " & a & " selected
end sub
Once you know the table no where you want add the rows
use the following
Sub enternewrow()
'
Dim y
Dim a, b, c
ActiveDocument.Unprotect
'count the number of rows in the table where 1 is
replaced by the table no.
y = ActiveDocument.Tables(1).Rows.Count
'select the last row 1st column
ActiveDocument.Tables(1).Cell(y, 1).Select
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.InsertRows 1
Selection.Collapse Direction:=wdCollapseStart
'redifine y to increase by 1 for the new row
which has been added
y = y + 1
' then select the last row, and column you want
to put text or field in
'change the 1 to which ever column you want
ActiveDocument.Tables(1).Cell(y, 1).Range.Text
= "hello"
'when using form fields always ensure noreset is
set to false
'in the protect statement otherwise when you
unprotect andadd you new
'rows and then protect the document anything
entered into any
'formfield will be reset to blank and the user
wont be happy
ActiveDocument.Protect Password:="",
NoReset:=False, Type:= _
wdAllowOnlyFormFields
End Sub
if you still want to use the autotext method then its the
same principle as follows.
Sub enternewrow()
'
Dim y
Dim a, b, c
ActiveDocument.Unprotect
'count the number of rows in the table where 1 is
replaced by the table no.
y = ActiveDocument.Tables(1).Rows.Count
'select the last row 1st column
ActiveDocument.Tables(1).Cell(y, 1).Select
Selection.MoveDown Unit:=wdLine, Count:=1
Selection.InsertRows 1
'when using autotext ensure you always save the
autotext entry
'in the template of the document and not the
normal.dot that way the
'autotext goes with the template and is always
available.
'Also always ensure you include:- RichText:=True
this
'means any formatted text remains as it was when
placed in the auto text
ActiveDocument.AttachedTemplate.AutoTextEntries
("singlewitness").Insert Where _
:=Selection.Range, RichText:=True 'Insert
autotext entry
'when using form fields always ensure noreset is
set to false
'in the protect statement otherwise when you
unprotect andadd you new
'rows and then protect the document anything
entered into any
'formfield will be reset to blank and the user
wont be happy
ActiveDocument.Protect Password:="",
NoReset:=False, Type:= _
wdAllowOnlyFormFields
End Sub
then when you have this working just set varibles in
relation to which checkbox is selected so the insert new
row loops how evermany times you want.
If you get stuck repost.
paul