Reply
 
Thread Tools Display Modes
  #1   Report Post  
CW
 
Posts: n/a
Default Can I control navigation from one cell to another?

1. Is it possible to program a table cell so that upon exit from it, the
cursor will go to another particular specified cell?
2. Can I control whether the cursor moves downwards rather than to the right
upon cell exit (as is possible in Excel)?
  #2   Report Post  
Jay Freedman
 
Posts: n/a
Default Can I control navigation from one cell to another?

CW wrote:
1. Is it possible to program a table cell so that upon exit from it,
the cursor will go to another particular specified cell?
2. Can I control whether the cursor moves downwards rather than to
the right upon cell exit (as is possible in Excel)?


If you're working in a protected form built in a table, then see
http://word.mvps.org/FAQs/TblsFldsFms/SetTabOrder.htm. The macros there work
entirely on the principles of form fields, their bookmark names, and their
exit macros -- the fact that the fields are in a table is purely
coincidental and not necessary.

Outside of a protected form, working with a bog-standard table, it would be
*possible* but difficult and error-prone to write a macro to look at which
cell contains the cursor and move accordingly. How would the macro "know"
which cell should have the special behavior and where the "next" cell is?
What if the user adds or deletes rows, merges cells, or does any of the
strange and wonderful things that Word allows? Bookmarked cells are a
possibility, but bookmarks are fragile and easily deleted.

To make the cursor move downward in *all* tables (at least ones that don't
contain merged or split cells, which give VBA fits), you can install this
macro. To restrict it to documents based on a specific template, store the
macro in that template; to have it work in all documents, store it in
Normal.dot or a global template in the Startup folder.

Sub NextCell()
Dim numRows As Long, numCols As Long
Dim thisRow As Long, thisCol As Long

' shouldn't need this, but I'm paranoid...
If Not Selection.Information(wdWithInTable) Then
Exit Sub
End If

' some of this stuff fails if the table
' contains any merged or split cells
On Error GoTo oops

numRows = Selection.Tables(1).Rows.Count
numCols = Selection.Tables(1).Columns.Count
thisRow = Selection.Information(wdStartOfRangeRowNumber)
thisCol = Selection.Information(wdStartOfRangeColumnNumber)

If (thisRow = numRows) And (thisCol = numCols) Then
' this is the bottom right cell...
' do the built-in behavior
Selection.Tables(1).Rows.Add
Selection.Tables(1).Cell(thisRow + 1, 1).Select
Else
If (thisRow = numRows) Then
' go to top of next column
Selection.Tables(1).Cell(1, thisCol + 1).Select
Else
' move down one cell
Selection.Tables(1).Cell(thisRow + 1, thisCol).Select
End If
End If

Exit Sub
oops:
MsgBox "Macro can't work with merged/split table cells", _
vbOKOnly + vbCritical, "Can't do it..."
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org


  #3   Report Post  
Tony Jollans
 
Posts: n/a
Default Can I control navigation from one cell to another?

There is nothing built-in but it can be done with code.You need to code a
macro called NextCell which will automatically run in response to pressing
Tab in a table cell, and which can determine what should be done according
to whatever criteria you choose.

--
Enjoy,
Tony


"CW" wrote in message
...
1. Is it possible to program a table cell so that upon exit from it, the
cursor will go to another particular specified cell?
2. Can I control whether the cursor moves downwards rather than to the

right
upon cell exit (as is possible in Excel)?



  #4   Report Post  
CW
 
Posts: n/a
Default Can I control navigation from one cell to another?

Many thanks, Jay and Tony - I'll have a go with the macro - sounds promising.
(I love the inclusion of the "oops" bit!!!)

"Tony Jollans" wrote:

There is nothing built-in but it can be done with code.You need to code a
macro called NextCell which will automatically run in response to pressing
Tab in a table cell, and which can determine what should be done according
to whatever criteria you choose.

--
Enjoy,
Tony


"CW" wrote in message
...
1. Is it possible to program a table cell so that upon exit from it, the
cursor will go to another particular specified cell?
2. Can I control whether the cursor moves downwards rather than to the

right
upon cell exit (as is possible in Excel)?




  #5   Report Post  
CW
 
Posts: n/a
Default Can I control navigation from one cell to another?

Many thanks, Jay and Tony - I'll have a go with the macro - sounds promising.
(I love the inclusion of the "oops" bit!!!)


"Jay Freedman" wrote:

CW wrote:
1. Is it possible to program a table cell so that upon exit from it,
the cursor will go to another particular specified cell?
2. Can I control whether the cursor moves downwards rather than to
the right upon cell exit (as is possible in Excel)?


If you're working in a protected form built in a table, then see
http://word.mvps.org/FAQs/TblsFldsFms/SetTabOrder.htm. The macros there work
entirely on the principles of form fields, their bookmark names, and their
exit macros -- the fact that the fields are in a table is purely
coincidental and not necessary.

Outside of a protected form, working with a bog-standard table, it would be
*possible* but difficult and error-prone to write a macro to look at which
cell contains the cursor and move accordingly. How would the macro "know"
which cell should have the special behavior and where the "next" cell is?
What if the user adds or deletes rows, merges cells, or does any of the
strange and wonderful things that Word allows? Bookmarked cells are a
possibility, but bookmarks are fragile and easily deleted.

To make the cursor move downward in *all* tables (at least ones that don't
contain merged or split cells, which give VBA fits), you can install this
macro. To restrict it to documents based on a specific template, store the
macro in that template; to have it work in all documents, store it in
Normal.dot or a global template in the Startup folder.

Sub NextCell()
Dim numRows As Long, numCols As Long
Dim thisRow As Long, thisCol As Long

' shouldn't need this, but I'm paranoid...
If Not Selection.Information(wdWithInTable) Then
Exit Sub
End If

' some of this stuff fails if the table
' contains any merged or split cells
On Error GoTo oops

numRows = Selection.Tables(1).Rows.Count
numCols = Selection.Tables(1).Columns.Count
thisRow = Selection.Information(wdStartOfRangeRowNumber)
thisCol = Selection.Information(wdStartOfRangeColumnNumber)

If (thisRow = numRows) And (thisCol = numCols) Then
' this is the bottom right cell...
' do the built-in behavior
Selection.Tables(1).Rows.Add
Selection.Tables(1).Cell(thisRow + 1, 1).Select
Else
If (thisRow = numRows) Then
' go to top of next column
Selection.Tables(1).Cell(1, thisCol + 1).Select
Else
' move down one cell
Selection.Tables(1).Cell(thisRow + 1, thisCol).Select
End If
End If

Exit Sub
oops:
MsgBox "Macro can't work with merged/split table cells", _
vbOKOnly + vbCritical, "Can't do it..."
End Sub

--
Regards,
Jay Freedman
Microsoft Word MVP FAQ: http://word.mvps.org



Reply
Thread Tools
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
In Word, Changing the margins for text in the cell Grumakle Tables 3 November 12th 05 05:45 PM
How to wrap text from cell to cell in a table. Jon Coulson Tables 2 August 8th 05 09:12 PM
Placing 1st table into a cell within 2nd table kathryngriffin1962 Tables 2 June 2nd 05 04:09 AM
setting cell width Hilary Microsoft Word Help 1 February 15th 05 09:31 AM
word table cell resize or word table cell size change or word table change cell size [email protected] Tables 0 January 13th 05 09:55 PM


All times are GMT +1. The time now is 07:15 PM.

Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 Microsoft Office Word Forum - WordBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Word"