Microsoft Office Tutorials and References
In Depth Information
Tables: Changing the Tab Direction
View the Appendix to learn how to store this procedure
in a Standard module.
Option explicit¶
' * * * * *¶
Sub NextCell()¶
'Make sure the selection is in a table¶
If Selection.Information(wdWithInTable) Then¶
'Variable declaration¶
Dim rcount As Long, ccount As Long¶
Dim ri As Long, ci As Long¶
Dim tbl As Word.Table¶
Set tbl = Selection.Tables(1)¶
'Where is selection?:¶
'In which row is the selection?¶
ri = Selection.Rows(1).Index¶
'And in which column?¶
ci = Selection.Columns(1).Index¶
'How many rows are there?¶
rcount = tbl.Rows.Count¶
'And how many columns?¶
ccount = tbl.Columns.Count¶
'If selection is not in the last row¶
If ri < rcount Then¶
'Move down to the next cell¶
tbl.Cell(ri + 1, ci).Select¶
'If it is in the last table cell¶
ElseIf ri = rcount And ci = ccount Then¶
'Variable declaration¶
Dim rng As Word.Range¶
Set rng = tbl.Range¶
'Move outside the table¶
rng.Collapse wdCollapseEnd¶
rng.Select¶
'If the last row, but not the last column¶
ElseIf ri = rcount Then¶
'Move to the top of the next column¶
tbl.Cell(1, ci + 1).Select¶
Else¶
'An unexpected situation has occurred¶
MsgBox "There's a problem"¶
End If¶
End If¶
End Sub¶
Wrd
The macro runs automatically.
Search JabSto ::




Custom Search