setup
i want to jump to the end of SoA tables with one click of the mouse. is there a way to do that?
solution
the plan
- if not in table, go forward to the nearest table.
- select the table. move right.
programming language & module(s)
- VBA
file preps
make the doc to be processed the active document, i.e. the one where the cursor currently is in.
variables to customize
none.
the script
go2AftTbl
| Sub go2AftTbl() | |
| Dim safeCount As Long | |
| System.Cursor = wdCursorWait | |
| Application.ScreenUpdating = False | |
| With Selection | |
| If .Information(wdWithInTable) = False Then | |
| go2NextTbl | |
| End If | |
| selTbl | |
| .MoveRight wdCharacter, 1 | |
| End With | |
| System.Cursor = wdCursorNormal | |
| Application.ScreenUpdating = True | |
| End Sub | |
| Sub go2NextTbl() | |
| Dim doc As Document | |
| Dim selStart, selEnd, safeCount As Long | |
| Application.ScreenUpdating = False | |
| System.Cursor = wdCursorWait | |
| Set doc = ActiveDocument | |
| safeCount = 0 | |
| If doc.Tables.Count = 0 Then | |
| MsgBox "there's NO table in this doc." | |
| Else | |
| With Selection | |
| If selStart >= doc.Tables(doc.Tables.Count).Range.Start Then | |
| MsgBox "there's no table after this one." | |
| doc.Range(selStart, selEnd).Select | |
| Exit Sub | |
| Else | |
| If .Information(wdWithInTable) = True Then | |
| selTbl | |
| .MoveRight wdCharacter, 1 | |
| End If | |
| Do While safeCount < 5000 ' customize here if needed. | |
| safeCount = safeCount + 1 | |
| If .Information(wdWithInTable) = False Then | |
| .MoveDown wdParagraph, 1 | |
| Else | |
| selTbl | |
| .MoveLeft wdCharacter, 1 | |
| Exit Sub | |
| End If | |
| Loop | |
| End If | |
| End With | |
| End If | |
| System.Cursor = wdCursorNormal | |
| Application.ScreenUpdating = True | |
| End Sub | |
| Sub selTbl() | |
| Selection.Tables(1).Select | |
| End Sub |
output
the cursor's now at the end of the current table or the nearest table going forward.
note to self
none.