A Microsoft Word forum. Microsoft Office Word Forum - WordBanter

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

Go Back   Home » Microsoft Office Word Forum - WordBanter forum » Microsoft Word Newsgroups » Tables
Site Map Home Register Authors List Search Today's Posts Mark Forums Read Web Partners

How do I lock a table (no more rows at bottom)?



 
 
Thread Tools Display Modes
  #1  
Old November 4th 09, 03:36 PM posted to microsoft.public.word.tables
Melissa at boa
external usenet poster
 
Posts: 1
Default How do I lock a table (no more rows at bottom)?

Hi, i'm using word 07 and need to prevent my last table row from creating
more rows when I tab. I have 3 small tables all on one page and may need to
merge these into one table.

1. How do I lock my bottom table row from adding more lines when I try to
tab to the next table.
2. If necessary, how do I merge two tables?

Thank you VERY much!
Ads
  #2  
Old November 4th 09, 04:22 PM posted to microsoft.public.word.tables
Jay Freedman
external usenet poster
 
Posts: 9,855
Default How do I lock a table (no more rows at bottom)?

Melissa at boa wrote:
Hi, i'm using word 07 and need to prevent my last table row from
creating more rows when I tab. I have 3 small tables all on one page
and may need to merge these into one table.

1. How do I lock my bottom table row from adding more lines when I
try to tab to the next table.
2. If necessary, how do I merge two tables?

Thank you VERY much!


For question 1, you can install the following macro in the template for this
kind of document (see http://www.gmayor.com/installing_macro.htm if needed):

Sub NextCell()
Dim thisRow As Integer, thisCol As Integer
Dim thisTable As Table, iTbl As Table
Dim thisTableIdx As Long


Set thisTable = Selection.Tables(1)
thisTableIdx = ActiveDocument.Range(0, _
thisTable.Range.End).Tables.Count
thisRow = Selection.Information(wdEndOfRangeRowNumber)
thisCol = Selection.Information(wdEndOfRangeColumnNumber)

If Not ((thisRow = thisTable.Rows.Count) And _
(thisCol = thisTable.Columns.Count)) Then
Selection.MoveRight Unit:=wdCell
Else
If thisTableIdx ActiveDocument.Tables.Count Then
' there is another table to go to
ActiveDocument.Tables(thisTableIdx + 1).Cell(1, 1).Select
Selection.Collapse wdCollapseStart
End If
End If
End Sub

Note that normally (unless you're working in a protected form document and
there is a form field in the next table) you can't "tab to the next table".
The macro makes that possible.

For question 2, just delete the paragraph mark(s) between the tables to make
them into one table. This is easier to control if you can see the paragraph
marks; clicking the button switches them on and off.

--
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.


  #3  
Old November 5th 09, 03:41 AM posted to microsoft.public.word.tables
Jay Freedman
external usenet poster
 
Posts: 9,855
Default How do I lock a table (no more rows at bottom)?

On Wed, 4 Nov 2009 06:36:01 -0800, Melissa at boa Melissa at
wrote:

Hi, i'm using word 07 and need to prevent my last table row from creating
more rows when I tab. I have 3 small tables all on one page and may need to
merge these into one table.

1. How do I lock my bottom table row from adding more lines when I try to
tab to the next table.
2. If necessary, how do I merge two tables?

Thank you VERY much!


For the first question, you can't "lock" the table row, but you can
install this macro in your template (see
http://www.gmayor.com/installing_macro.htm if needed) to change the
behavior of the tab key when the cursor is in the last cell of a
table:

Sub NextCell()
Dim oTbl As Table
Dim tblIndex As Long
Dim thisRow As Long, thisCol As Long

Set oTbl = Selection.Tables(1)
tblIndex = ActiveDocument.Range(0, oTbl.Range.End).Tables.Count

thisRow = Selection.Information(wdEndOfRangeRowNumber)
thisCol = Selection.Information(wdEndOfRangeColumnNumber)

If Not ((thisRow = oTbl.Rows.Count) And _
(thisCol = oTbl.Columns.Count)) Then
Selection.MoveRight Unit:=wdCell, Count:=1
Else
' If this isn't the last table, jump to the next table
If tblIndex ActiveDocument.Tables.Count Then
ActiveDocument.Tables(tblIndex + 1).Cell(1, 1).Select
Selection.Collapse wdCollapseStart
End If
End If
End Sub

The other thing is that normally you can't "tab to the next table"
unless you have a protected form with form fields in the table cells.
But the above macro will take care of that, too.

For your second question, just delete any text and paragraph marks
from between the two tables to merge them. This is easier to do if you
can see the paragraph marks, so click the button to turn them on and
off.

--
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.
  #4  
Old November 11th 09, 11:30 PM posted to microsoft.public.word.tables
Larry Sulky
external usenet poster
 
Posts: 7
Default How do I lock a table (no more rows at bottom)?

On Nov 4, 10:22*am, "Jay Freedman" wrote:
* * If Not ((thisRow = thisTable.Rows.Count) And _
* * * * * * (thisCol = thisTable.Columns.Count)) Then
* * * * Selection.MoveRight Unit:=wdCell
* * Else


Say, Jay, I adapted this code to something I'm doing and I've got a
problem. My table is two columns, and in the last two rows the cells
in the right column are merged:

+----+-----+
| A | |
+----+ B |
| C | |
+----+-----+

So the Selection.MoveRight Unit:=wdCell moves the selection from Cell
A to Cell B, then to Cell C, then back to Cell B. Cell A is at
(r1,c1), B is at (r1,c2), and C is at (r2,c1). There is no cell that
has the maximum row count and the maximum column count. That is, there
is no cell at (r2,c2). So the condition in the snippet above is true
for cell B both times the selection hits it, and on the second time,
the MoveRight creates a new row.

Any way to prevent that new row from being created?
TIA
---larry
  #5  
Old November 12th 09, 02:24 AM posted to microsoft.public.word.tables
Jay Freedman
external usenet poster
 
Posts: 9,855
Default How do I lock a table (no more rows at bottom)?

There's nothing general you can do that will work regardless of
whether any particular table has merged cells or not. If you know with
absolute certainty what your table looks like (because you set it up
in a template and don't let anyone alter it), then you can program to
that specific circumastance. Instead of checking Rows.Count and
Columns.Count, check for the specific cell coordinates of cell C.

You would also want to start the event handler with a check for
whether the ActivDocument.AttachedTemplate is the one that contains
the table; if not, immediately Exit Sub. That will take care of the
possibility that a document based on your template and one based on a
different template are open at the same time (because the event
handler fires for all documents).

--
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.

On Wed, 11 Nov 2009 14:30:09 -0800 (PST), Larry Sulky
wrote:

On Nov 4, 10:22*am, "Jay Freedman" wrote:
* * If Not ((thisRow = thisTable.Rows.Count) And _
* * * * * * (thisCol = thisTable.Columns.Count)) Then
* * * * Selection.MoveRight Unit:=wdCell
* * Else


Say, Jay, I adapted this code to something I'm doing and I've got a
problem. My table is two columns, and in the last two rows the cells
in the right column are merged:

+----+-----+
| A | |
+----+ B |
| C | |
+----+-----+

So the Selection.MoveRight Unit:=wdCell moves the selection from Cell
A to Cell B, then to Cell C, then back to Cell B. Cell A is at
(r1,c1), B is at (r1,c2), and C is at (r2,c1). There is no cell that
has the maximum row count and the maximum column count. That is, there
is no cell at (r2,c2). So the condition in the snippet above is true
for cell B both times the selection hits it, and on the second time,
the MoveRight creates a new row.

Any way to prevent that new row from being created?
TIA
---larry

  #6  
Old November 12th 09, 05:53 PM posted to microsoft.public.word.tables
Larry Sulky
external usenet poster
 
Posts: 7
Default How do I lock a table (no more rows at bottom)?

On Nov 11, 8:24*pm, Jay Freedman wrote:
There's nothing general you can do that will work regardless of
whether any particular table has merged cells or not. If you know with
absolute certainty what your table looks like (because you set it up
in a template and don't let anyone alter it), then you can program to
that specific circumastance. Instead of checking Rows.Count and
Columns.Count, check for the specific cell coordinates of cell C.

You would also want to start the event handler with a check for
whether the ActivDocument.AttachedTemplate is the one that contains
the table; if not, immediately Exit Sub. That will take care of the
possibility that a document based on your template and one based on a
different template are open at the same time (because the event
handler fires for all documents).

--
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.

On Wed, 11 Nov 2009 14:30:09 -0800 (PST), Larry Sulky



wrote:
On Nov 4, 10:22*am, "Jay Freedman" wrote:
* * If Not ((thisRow = thisTable.Rows.Count) And _
* * * * * * (thisCol = thisTable.Columns.Count)) Then
* * * * Selection.MoveRight Unit:=wdCell
* * Else


Say, Jay, I adapted this code to something I'm doing and I've got a
problem. My table is two columns, and in the last two rows the cells
in the right column are merged:


+----+-----+
| *A *| * * *|
+----+ *B *|
| *C *| * * *|
+----+-----+


So the Selection.MoveRight Unit:=wdCell moves the selection from Cell
A to Cell B, then to Cell C, then back to Cell B. Cell A is at
(r1,c1), B is at (r1,c2), and C is at (r2,c1). There is no cell that
has the maximum row count and the maximum column count. That is, there
is no cell at (r2,c2). So the condition in the snippet above is true
for cell B both times the selection hits it, and on the second time,
the MoveRight creates a new row.


Any way to prevent that new row from being created?
TIA
---larry- Hide quoted text -


- Show quoted text -


Thanks, Jay. As it happens I don't know the exact shape of the table;
the macro has to work on any shape. So instead of using a MoveRight
command, I've changed my approach to use a two-dimensional array to
capture values for cells. In the following sample code, I'm capturing
the vertical alignment and background colour of cells prior to
changing the table style to Table Normal (which clobbers those two
attributes, among many others). Then I can restore those attributes
cell by cell. It's working fine for my purposes, and sidesteps the
issue of accidentally creating new rows.
---larry

Sub CTS()
'''''''''
On Error GoTo ErrMsg:

If Not Selection.Information(wdWithInTable) Then Exit Sub

Dim myTbl As Table
Dim myRow As Long
Dim myCol As Long
Dim maxRow As Long
Dim maxCol As Long

Set myTbl = Selection.Tables(1)
maxRow = myTbl.Rows.Count
maxCol = myTbl.Columns.Count

'''\ Set a two-dimensional array.
' Unfortunately, we can't set the values _
using variables, but we also can't set _
a multidimensional array without values, _
and in any case we can't ReDim both _
dimensions to variable values. So we _
just have to set fixed values and hope _
that they're big enough.
Dim cellColour(100, 100) As Double
Dim cellVertAlign(100, 100) As Double
'''/

On Error GoTo NoCell1:
For myRow = 1 To maxRow
For myCol = 1 To maxCol
cellColour(myRow, myCol) = _
myTbl.Cell(myRow, myCol).Shading.BackgroundPatternColor
cellVertAlign(myRow, myCol) = _
myTbl.Cell(myRow, myCol).VerticalAlignment
NoCell1: ' If a cell doesn't exist (because of merging)
Next
Next

On Error GoTo ErrMsg:

With myTbl
.Style = "Table Normal"
.ApplyStyleHeadingRows = False
.ApplyStyleLastRow = False
.ApplyStyleFirstColumn = False
.ApplyStyleLastColumn = False
End With

On Error GoTo NoCell2:
For myRow = 1 To maxRow
For myCol = 1 To maxCol
myTbl.Cell(myRow, myCol).Shading.BackgroundPatternColor = _
cellColour(myRow, myCol)
myTbl.Cell(myRow, myCol).VerticalAlignment = _
cellVertAlign(myRow, myCol)
NoCell2: ' If a cell doesn't exist (because of merging)
Next
Next

On Error GoTo ErrMsg:

GoTo Bye:

ErrMsg:
MsgBox "Whatever",,"ERROR"

Bye:
'''''''
End Sub

  #7  
Old November 12th 09, 08:31 PM posted to microsoft.public.word.tables
Larry Sulky
external usenet poster
 
Posts: 7
Default How do I lock a table (no more rows at bottom)?

Correction: Where I've said "On Error GoTo NoCell1" and "....
NoCell2", I should have said "On Error Resume Next"; and the NoCell1
and NoCell2 labels aren't necessary.
 




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I add, say, 15 rows to the bottom of a table? Mealybug Tables 1 November 14th 08 01:14 AM
how do I lock a table at the bottom of the 1st page Donna Tables 2 April 5th 08 12:35 PM
how do i lock rows in a table? SJ Tables 1 June 8th 06 10:33 AM
Lock formatting for rows in a table? Smiley Guy Microsoft Word Help 4 March 9th 06 01:26 PM
How to lock columns/rows in a table in word Mamma Boel Tables 6 May 17th 05 09:55 PM


All times are GMT +1. The time now is 06:48 AM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
Copyright 2004-2019 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.