View Single Post
  #11  
Old June 17th, 2007, 06:54 AM posted to microsoft.public.word.tables
alborg
external usenet poster
 
Posts: 74
Default How do I lock a table cell in Word?

Hi Kathryn:

Ok... here goes...

1. Place table on your template. For this example, place a 2 row, 2 column
template.
2. Click on View→ Toolbars→ check on the “Forms” toolbar
3. Click on the “ab” icon repeatedly to add in a Text Form Field inside each
of the 4 table cells. Leave the right sided padlock in the “unlocked” or flat
position.
4. Click on View- Toolbars- check on the "Visual Basic" toolbar
5. Now click on the Visual Basic icon to go to the VB environment.
6. Once there, click on Tools- References and make sure that you have some
of the ones you'll most likely need (to avoid errors)-

• Visual Basic for Applications
• Microsoft Word 11.0 Object Library
• OLE Automation
• Microsoft Office 11.0 Object Library
• Microsoft DAO 3.6 Object Library
• Microsoft Visual Basic for Applications Extensibility 5.3

Some other ones that I occasionally use depending on what I"m programming-

• Microsoft ActiveX Data Objects 2.8 Library
• Microsoft Jet and Replication Objects 2.6 Library
• Microsoft Calendar Control 11.0
• Microsoft Forms 2.0 Object Library

(Depending on your Word version, the version number could change, s.a.
Microsoft Office 9.0 for Word 2000)
7. Now click on View→ Project Explorer
8. Right click on your project name, then select Insert→ Module
9. Rename the module “AutoMacros” and add the following Sub routines-

Sub addrow()
Dim rownum As Integer, i As Integer
response = MsgBox("Add new row?", vbQuestion + vbYesNo)
If response = vbYes Then
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.Table s(1).Rows.Count,
ActiveDocument.Tables(1).Columns.Count - 1).Range.FormFields(1).EntryMacro =
"addinfo"
ActiveDocument.Tables(1).Cell(ActiveDocument.Table s(1).Rows.Count,
ActiveDocument.Tables(1).Columns.Count).Range.Form Fields(1).ExitMacro =
"addrow"
'ActiveDocument.Tables(1).Cell(ActiveDocument.Tabl es(1).Rows.Count,
1).Range.FormFields(1).Select
ActiveDocument.Protect Type:=wdAllowOnlyFormFields, NoReset:=True
End If
End Sub

10. Save your work.
11. Now get out of the Visual Basic platform and go back to your table.
Right click on both of the RIGHT sided Text Form Fields, then Properties→
“Run macro on”→ then in the “Exit” combobox choose your new subroutine
(“addrow”).

Finished! Now lock your form (i.e. click on/indent the padlock) and try
landing, then exiting on one of the activated fields. Should work. Cool huh?
That’s programming…

Cheers,
Al


"Kathryn Pundt" wrote:

Okay, I'll let you know how it goes.

As for the "how to programmatically add new rows with textboxes "
instructions, I don't know how to use user-programming. But, am very willing
to learn if you have the time...

"alborg" wrote:

Hi Kathryn:

Yup... that's it. You gotta "lock" (i.e. disable) the textbox controls, not
the table.

BTW, the idea on how to programmatically add new rows with textboxes was
obtained from one of the most popular threads (check Show- Helpful threads)
with the title "Subject: How to insert multiple rows in tables". It
really is cool. The way I did it is the slightly improved version that works
in Word 2000/2002/2003 since the textbox "name" method didn't work in the MS
Word 2000 due to a Word bug.

Cheers,
AL

"Kathryn Pundt" wrote:

I'm am not sure I understand. This is what I understand you are trying to
convey.

Create a table. Insert textboxes into the table? Then, lock the texbox?

"Kathryn Pundt" wrote:

I am creating a template in Word using tables. I want to lock certain cells
so no one can alter the contents.