C
clh
I am trying to insert a table row (which has been saved
as an AutoText entry) at the end of a specific table via
macro. The row contains text and fields, so I can't just
add a row at the end of the table in the normal way.
At the top of the table I want to add the row to is a
checkbox which my macro is linked to. If the checkbox is
checked, when the user tabs out of the checkbox, the
macro will run and the new row needs to be added using
the AutoText entry. If the checkbox is not checked,
nothing should happen when the user tabs out of the
checkbox.
When I run the template and the "check" the checkbox, I
end up with an error on the line of code that is supposed
to insert the AutoText entry. I can't figure out why I'm
getting the error. The AutoText entry is saved to the
template I am working on, not to the Normal template.
Here's my code for this macro:
- - - - - - - - - - - - - - - - - - - - - - - -
Sub Add1Row()
Dim intRowsInTable As Integer
' If checkbox is checked, add AutoText row to end of
table 5
If ActiveDocument.FormFields("checkbox1").CheckBox.Value
= True Then
' Unlock the document
ActiveDocument.Unprotect
' Count the number of rows in the table
intRowsInTable = ActiveDocument.Tables(1).Rows.Count
' Select the first column in the last row
ActiveDocument.Tables(1).Cell(intRowsInTable,
1).Select
Selection.MoveDown unit:=wdLine, Count:=1
Selection.InsertRows 1
' Insert AutoText entry
ActiveDocument.AttachedTemplate.AutoTextEntries
("AddRowATEntry").Insert where:= _
Selection.Range, RichText:=True
' Lock the document
ActiveDocument.Protect Type:=wdAllowOnlyFormFields
End If
' If checkbox is not checked, do nothing
If ActiveDocument.FormFields("checkbox1").CheckBox.Value
= False Then
' Nothing
End If
End Sub
- - - - - - - - - - - - - - - - - - - - - - - -
I did get some help in response to my initial post, but
I'm still doing something wrong (obviously). Any help
would be GREATLY appreciated!!!
Thanks!
Cheryl
as an AutoText entry) at the end of a specific table via
macro. The row contains text and fields, so I can't just
add a row at the end of the table in the normal way.
At the top of the table I want to add the row to is a
checkbox which my macro is linked to. If the checkbox is
checked, when the user tabs out of the checkbox, the
macro will run and the new row needs to be added using
the AutoText entry. If the checkbox is not checked,
nothing should happen when the user tabs out of the
checkbox.
When I run the template and the "check" the checkbox, I
end up with an error on the line of code that is supposed
to insert the AutoText entry. I can't figure out why I'm
getting the error. The AutoText entry is saved to the
template I am working on, not to the Normal template.
Here's my code for this macro:
- - - - - - - - - - - - - - - - - - - - - - - -
Sub Add1Row()
Dim intRowsInTable As Integer
' If checkbox is checked, add AutoText row to end of
table 5
If ActiveDocument.FormFields("checkbox1").CheckBox.Value
= True Then
' Unlock the document
ActiveDocument.Unprotect
' Count the number of rows in the table
intRowsInTable = ActiveDocument.Tables(1).Rows.Count
' Select the first column in the last row
ActiveDocument.Tables(1).Cell(intRowsInTable,
1).Select
Selection.MoveDown unit:=wdLine, Count:=1
Selection.InsertRows 1
' Insert AutoText entry
ActiveDocument.AttachedTemplate.AutoTextEntries
("AddRowATEntry").Insert where:= _
Selection.Range, RichText:=True
' Lock the document
ActiveDocument.Protect Type:=wdAllowOnlyFormFields
End If
' If checkbox is not checked, do nothing
If ActiveDocument.FormFields("checkbox1").CheckBox.Value
= False Then
' Nothing
End If
End Sub
- - - - - - - - - - - - - - - - - - - - - - - -
I did get some help in response to my initial post, but
I'm still doing something wrong (obviously). Any help
would be GREATLY appreciated!!!
Thanks!
Cheryl