"Insert" button

Z

Zed Rafi

Hello,

I'm currently building a template, in which I'd like to create a macro to
insert a block of formatted text automatically by clicking on a button.

Here's what i want to do :

'File No. X Client name ABC

Contact name: <TextField>
Contact phone number: <TextField>' --> name and phone of the contact are
in a table.

I'd like to create a button which inserts an addiontal contact table
(contact name + field and contact phone no. + field), in case information
needs to be entered for more than 1 contact.

Any thoughts?
thanks a lot
 
D

Doug Robbins

It sounds like this is a data entry application, more than a template from
which multiple documents will be created?

Maybe the following code will be of use to you:

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
--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 
Z

Zed Rafi

It sounds like this is a data entry application, more than a template from
which multiple documents will be created?

no, not really, it's really a template i want to create.
what i want to do is create a printable form, which will be included in our
paper files. I want to create a contact sheet which comprises, by default, a
table with cells only for 1 contact person. If more than one contact needs
to be entered, i'd like to click on a button to create another array of
cells in the table, the first column of this new array of cells already
comrpising information like "Second contact name" and "Second contact
phone", and the facing cells of the array comprising blank text fields
enabling input therein. I'd like this sequence to be able to be repeated for
a third, fourth, etc... contact person.

there'a number of other information in the template.

i hope my question is more clear now.
thanks
 
D

Doug Robbins

The following code will add a row to the first table in the document and
insert Contact # Name in the first cell in that row.

With ActiveDocument.Tables(1)
.Rows.Add
.Cell(.Rows.Count, 1).Range.InsertBefore "Contact " & .Rows.Count & "
Name:"
End With

Changing # to second, third, fourth etc. can be done, but it's a bit more
work.

--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.

Hope this helps,
Doug Robbins - Word MVP
 

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