A Microsoft Office (Excel, Word) forum. OfficeFrustration

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 » OfficeFrustration forum » Microsoft Word » Tables
Site Map Home Register Authors List Search Today's Posts Mark Forums Read  

Can I control navigation from one cell to another?



 
 
Thread Tools Display Modes
  #1  
Old October 18th, 2005, 04:31 PM
CW
external usenet poster
 
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  
Old October 18th, 2005, 07:28 PM
Jay Freedman
external usenet poster
 
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  
Old October 18th, 2005, 07:35 PM
Tony Jollans
external usenet poster
 
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  
Old October 19th, 2005, 12:01 PM
CW
external usenet poster
 
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  
Old October 19th, 2005, 12:02 PM
CW
external usenet poster
 
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



 




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 Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Empty cell control Danno Worksheet Functions 0 June 1st, 2005 12:12 AM
GET.CELL Biff Worksheet Functions 2 November 24th, 2004 07:16 PM
IF E3 & E10 = TRUE set this cell to "Yes", else set to "No" Timothy L Worksheet Functions 5 August 27th, 2004 02:28 AM
Page Navigation Control Jeff Publisher 1 May 19th, 2004 11:06 PM
Convert a Cell Reference to Text Chuck Buker Worksheet Functions 6 September 22nd, 2003 05:04 PM


All times are GMT +1. The time now is 01:02 PM.


Powered by vBulletin® Version 3.6.4
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 OfficeFrustration.
The comments are property of their posters.