Home |
Search |
Today's Posts |
#1
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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
|
|||
|
|||
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 | |
|
|
Similar Threads | ||||
Thread | Forum | |||
In Word, Changing the margins for text in the cell | Tables | |||
How to wrap text from cell to cell in a table. | Tables | |||
Placing 1st table into a cell within 2nd table | Tables | |||
setting cell width | Microsoft Word Help | |||
word table cell resize or word table cell size change or word table change cell size | Tables |