|
|
|
date: Fri, 6 Jan 2006 10:16:04 -0800,
group: microsoft.public.word.vba.customization
back
Using VBA insert table row with text form fields
I have a document form (protected) with a table containing three rows. I
need to be able to run a macro that inserts a new row in the table and
inserts a text form field in each row. The macro shown below does that,
however, only the first of the three text form fields is given a bookmark
name, i.e. Text12. How do I get the remaining two text form fields to have a
bookmark name, i.e., Text13 and Text14?
Sub NewRow()
Dim rownum As Integer, i As Integer
ActiveDocument.Unprotect Password:="XYZ"
ActiveDocument.Tables(1).Rows.Add
rownum = ActiveDocument.Tables(1).Rows.Count
For i = 1 To ActiveDocument.Tables(1).Columns.Count
ActiveDocument.FormFields.Add
Range:=ActiveDocument.Tables(1).Cell(rownum, i).Range,
Type:=wdFieldFormTextInput
Next i
ActiveDocument.Tables(1).Cell(ActiveDocument.Tables(1).Rows.Count,
1).Range.FormFields(1).Select
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True,
Password:="XYZ"
End Sub
Thanks in advance for any and all assistance
sjane
date: Fri, 6 Jan 2006 10:16:04 -0800
author: sjane
Re: Using VBA insert table row with text form fields
See if this article helps:
http://word.mvps.org/FAQs/MacrosVBA/AssignNameToFmFld.htm
--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
sjane wrote:
> I have a document form (protected) with a table containing three
> rows. I need to be able to run a macro that inserts a new row in the
> table and inserts a text form field in each row. The macro shown
> below does that, however, only the first of the three text form
> fields is given a bookmark name, i.e. Text12. How do I get the
> remaining two text form fields to have a bookmark name, i.e., Text13
> and Text14?
>
> Sub NewRow()
>
> Dim rownum As Integer, i As Integer
> ActiveDocument.Unprotect Password:="XYZ"
> ActiveDocument.Tables(1).Rows.Add
> rownum = ActiveDocument.Tables(1).Rows.Count
> For i = 1 To ActiveDocument.Tables(1).Columns.Count
> ActiveDocument.FormFields.Add
> Range:=ActiveDocument.Tables(1).Cell(rownum, i).Range,
> Type:=wdFieldFormTextInput
> Next i
> ActiveDocument.Tables(1).Cell(ActiveDocument.Tables(1).Rows.Count,
> 1).Range.FormFields(1).Select
> ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True,
> Password:="XYZ"
>
> End Sub
>
> Thanks in advance for any and all assistance
>
> sjane
date: Fri, 6 Jan 2006 13:31:36 -0500
author: Jay Freedman
Re: Using VBA insert table row with text form fields
The following macro adds formfields with a bookmark name assigned to them:
Sub addrow()
'
' Macro created 02/02/03 by Doug Robbins
' To add a new row to a table containing formfields in every column
' automatically on exit from the last cell in the present last row of the
table
Dim rownum As Integer, i As Integer
ActiveDocument.Unprotect
ActiveDocument.Tables(1).Rows.Add
rownum = ActiveDocument.Tables(1).Rows.Count
For i = 1 To ActiveDocument.Tables(1).Columns.Count
ActiveDocument.FormFields.Add
Range:=ActiveDocument.Tables(1).Cell(rownum, i).Range,
Type:=wdFieldFormTextInput
Next i
ActiveDocument.Tables(1).Cell(ActiveDocument.Tables(1).Rows.Count,
ActiveDocument.Tables(1).Columns.Count).Range.FormFields(1).ExitMacro =
"addrow"
ActiveDocument.Tables(1).Cell(ActiveDocument.Tables(1).Rows.Count,
1).Range.FormFields(1).Select
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
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
"sjane" wrote in message
news:E17A6FD9-D393-40B5-B82E-DD224F3142FD@microsoft.com...
>I have a document form (protected) with a table containing three rows. I
> need to be able to run a macro that inserts a new row in the table and
> inserts a text form field in each row. The macro shown below does that,
> however, only the first of the three text form fields is given a bookmark
> name, i.e. Text12. How do I get the remaining two text form fields to
> have a
> bookmark name, i.e., Text13 and Text14?
>
> Sub NewRow()
>
> Dim rownum As Integer, i As Integer
> ActiveDocument.Unprotect Password:="XYZ"
> ActiveDocument.Tables(1).Rows.Add
> rownum = ActiveDocument.Tables(1).Rows.Count
> For i = 1 To ActiveDocument.Tables(1).Columns.Count
> ActiveDocument.FormFields.Add
> Range:=ActiveDocument.Tables(1).Cell(rownum, i).Range,
> Type:=wdFieldFormTextInput
> Next i
> ActiveDocument.Tables(1).Cell(ActiveDocument.Tables(1).Rows.Count,
> 1).Range.FormFields(1).Select
> ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True,
> Password:="XYZ"
>
> End Sub
>
> Thanks in advance for any and all assistance
>
> sjane
date: Fri, 6 Jan 2006 22:16:19 +0100
author: Doug Robbins - Word MVP
Re: Using VBA insert table row with text form fields
Doug - thank you for the prompt response - unfortunately, while the macro
added the row and text form fields to each of the columns in the row, only
the first text form field in the row had a bookmark name
"Doug Robbins - Word MVP" wrote:
> The following macro adds formfields with a bookmark name assigned to them:
>
> Sub addrow()
>
> '
>
> ' Macro created 02/02/03 by Doug Robbins
>
> ' To add a new row to a table containing formfields in every column
>
> ' automatically on exit from the last cell in the present last row of the
> table
>
> Dim rownum As Integer, i As Integer
>
> ActiveDocument.Unprotect
>
> ActiveDocument.Tables(1).Rows.Add
>
> rownum = ActiveDocument.Tables(1).Rows.Count
>
> For i = 1 To ActiveDocument.Tables(1).Columns.Count
>
> ActiveDocument.FormFields.Add
> Range:=ActiveDocument.Tables(1).Cell(rownum, i).Range,
> Type:=wdFieldFormTextInput
>
> Next i
>
> ActiveDocument.Tables(1).Cell(ActiveDocument.Tables(1).Rows.Count,
> ActiveDocument.Tables(1).Columns.Count).Range.FormFields(1).ExitMacro =
> "addrow"
>
> ActiveDocument.Tables(1).Cell(ActiveDocument.Tables(1).Rows.Count,
> 1).Range.FormFields(1).Select
>
> ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
>
>
>
> 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
>
> "sjane" wrote in message
> news:E17A6FD9-D393-40B5-B82E-DD224F3142FD@microsoft.com...
> >I have a document form (protected) with a table containing three rows. I
> > need to be able to run a macro that inserts a new row in the table and
> > inserts a text form field in each row. The macro shown below does that,
> > however, only the first of the three text form fields is given a bookmark
> > name, i.e. Text12. How do I get the remaining two text form fields to
> > have a
> > bookmark name, i.e., Text13 and Text14?
> >
> > Sub NewRow()
> >
> > Dim rownum As Integer, i As Integer
> > ActiveDocument.Unprotect Password:="XYZ"
> > ActiveDocument.Tables(1).Rows.Add
> > rownum = ActiveDocument.Tables(1).Rows.Count
> > For i = 1 To ActiveDocument.Tables(1).Columns.Count
> > ActiveDocument.FormFields.Add
> > Range:=ActiveDocument.Tables(1).Cell(rownum, i).Range,
> > Type:=wdFieldFormTextInput
> > Next i
> > ActiveDocument.Tables(1).Cell(ActiveDocument.Tables(1).Rows.Count,
> > 1).Range.FormFields(1).Select
> > ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True,
> > Password:="XYZ"
> >
> > End Sub
> >
> > Thanks in advance for any and all assistance
> >
> > sjane
>
>
>
date: Fri, 6 Jan 2006 13:46:02 -0800
author: sjane
Re: Using VBA insert table row with text form fields
Jay - thank you for your quick response, but I do not see how the information
contained in the article you referred me to can insert a bookmark name in the
text form fields that are added by my macro (which only gives a sequential
bookmark name to the first text form field in the first column - the
remaining two when double clicked to open have a blank for bookmark name. If
you have any other ideas, please do not hesitate to advise.
sjane
"Jay Freedman" wrote:
> See if this article helps:
>
> http://word.mvps.org/FAQs/MacrosVBA/AssignNameToFmFld.htm
>
> --
> Regards,
> Jay Freedman
> Microsoft Word MVP FAQ: http://word.mvps.org
> Email cannot be acknowledged; please post all follow-ups to the newsgroup so
> all may benefit.
>
> sjane wrote:
> > I have a document form (protected) with a table containing three
> > rows. I need to be able to run a macro that inserts a new row in the
> > table and inserts a text form field in each row. The macro shown
> > below does that, however, only the first of the three text form
> > fields is given a bookmark name, i.e. Text12. How do I get the
> > remaining two text form fields to have a bookmark name, i.e., Text13
> > and Text14?
> >
> > Sub NewRow()
> >
> > Dim rownum As Integer, i As Integer
> > ActiveDocument.Unprotect Password:="XYZ"
> > ActiveDocument.Tables(1).Rows.Add
> > rownum = ActiveDocument.Tables(1).Rows.Count
> > For i = 1 To ActiveDocument.Tables(1).Columns.Count
> > ActiveDocument.FormFields.Add
> > Range:=ActiveDocument.Tables(1).Cell(rownum, i).Range,
> > Type:=wdFieldFormTextInput
> > Next i
> > ActiveDocument.Tables(1).Cell(ActiveDocument.Tables(1).Rows.Count,
> > 1).Range.FormFields(1).Select
> > ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True,
> > Password:="XYZ"
> >
> > End Sub
> >
> > Thanks in advance for any and all assistance
> >
> > sjane
>
>
>
date: Fri, 6 Jan 2006 13:58:03 -0800
author: sjane
Re: Using VBA insert table row with text form fields
sjane was telling us:
sjane nous racontait que :
> Doug - thank you for the prompt response - unfortunately, while the
> macro added the row and text form fields to each of the columns in
> the row, only the first text form field in the row had a bookmark name
I do not know what is wrong with your system, but if I run Doug's macro as
is, I get a different name for each formfield (Text3, Text4, Text5, etc.)
However, try this variation, it will name each formfield according to the
row number and column number:
Sub addrow()
Dim rownum As Integer, i As Integer
Dim myFF As FormField
ActiveDocument.Unprotect
ActiveDocument.Tables(1).Rows.Add
rownum = ActiveDocument.Tables(1).Rows.Count
For i = 1 To ActiveDocument.Tables(1).Columns.Count
ActiveDocument.FormFields.Add _
Range:=ActiveDocument.Tables(1).Cell(rownum, i).Range, _
Type:=wdFieldFormTextInput
Set myFF = ActiveDocument.Tables(1).Cell(rownum, i).Range.FormFields(1)
myFF.Name = "Text_" & rownum & "_" & i
Set myFF = Nothing
Next i
ActiveDocument.Tables(1).Cell(ActiveDocument.Tables(1).Rows.Count, _
ActiveDocument.Tables(1).Columns.Count).Range.FormFields(1) _
.ExitMacro = "addrow"
ActiveDocument.Tables(1).Cell(ActiveDocument.Tables(1).Rows _
.Count, 1).Range.FormFields(1).Select
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End Sub
--
Salut!
_______________________________________
Jean-Guy Marcil - Word MVP
jmarcilREMOVE@CAPSsympatico.caTHISTOO
Word MVP site: http://www.word.mvps.org
date: Fri, 6 Jan 2006 17:39:58 -0500
author: Jean-Guy Marcil NoSpam@LeaveMeAlone
Re: Using VBA insert table row with text form fields
Jean-Guy - thank you for your assistance. Apparently my system does have a
problem which I am not certain how to address. After running your macro, in
the bookmark list I have new bookmark names which the macro created.
However, when you go to the specific text form field and double click on it,
the bookmark name box is blank. Thanks again.
sjane
"Jean-Guy Marcil" wrote:
> sjane was telling us:
> sjane nous racontait que :
>
> > Doug - thank you for the prompt response - unfortunately, while the
> > macro added the row and text form fields to each of the columns in
> > the row, only the first text form field in the row had a bookmark name
>
> I do not know what is wrong with your system, but if I run Doug's macro as
> is, I get a different name for each formfield (Text3, Text4, Text5, etc.)
>
> However, try this variation, it will name each formfield according to the
> row number and column number:
>
> Sub addrow()
>
> Dim rownum As Integer, i As Integer
> Dim myFF As FormField
>
> ActiveDocument.Unprotect
>
> ActiveDocument.Tables(1).Rows.Add
>
> rownum = ActiveDocument.Tables(1).Rows.Count
>
> For i = 1 To ActiveDocument.Tables(1).Columns.Count
>
> ActiveDocument.FormFields.Add _
> Range:=ActiveDocument.Tables(1).Cell(rownum, i).Range, _
> Type:=wdFieldFormTextInput
> Set myFF = ActiveDocument.Tables(1).Cell(rownum, i).Range.FormFields(1)
> myFF.Name = "Text_" & rownum & "_" & i
> Set myFF = Nothing
> Next i
>
> ActiveDocument.Tables(1).Cell(ActiveDocument.Tables(1).Rows.Count, _
> ActiveDocument.Tables(1).Columns.Count).Range.FormFields(1) _
> .ExitMacro = "addrow"
>
> ActiveDocument.Tables(1).Cell(ActiveDocument.Tables(1).Rows _
> .Count, 1).Range.FormFields(1).Select
>
> ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
>
>
> End Sub
>
> --
> Salut!
> _______________________________________
> Jean-Guy Marcil - Word MVP
> jmarcilREMOVE@CAPSsympatico.caTHISTOO
> Word MVP site: http://www.word.mvps.org
>
>
>
date: Mon, 9 Jan 2006 06:22:05 -0800
author: sjane
|
|