RE: Getting out of a table in VBA

Subject: RE: Getting out of a table in VBA
From: "Weissman, Jessica" <WeissmanJ -at- abacustech -dot- com>
To: Larry Landis <lawrence_landis -at- yahoo -dot- com>, "techwr-l -at- lists -dot- techwr-l -dot- com" <techwr-l -at- lists -dot- techwr-l -dot- com>
Date: Wed, 20 Jul 2011 12:16:06 -0400

Here is a kludgy method that works, assuming the cursor is still somewhere in the table you created. It moves to the last row of the table, then to the last cell of that row, and then down TWO lines.

If you move only one line you end up at the odd spot to the right of the last table row.

WdCollapseEnd just moves the selection to a single cursor at the end of the former selection. If you already have just a cursor it doesn't do anything visible.

You could cut this down to one move by calculating the number of cells to move, and then doing something like
Selection.Move unit = wdCell, Count = (calculated number of cells-1)

There are probably more sophisticated ways to do this, using the GoTo method of the selection. In all cases, the key is to get to the last cell of the table, then move down by two lines.

The cursor doesn't have to be in the first cell, since moves by unit that try to move by more units than exist (i.e. by 7 rows when you're already in the 6th row) just go to the max for that unit.

Also, you might want to look up the Information property. Lots of good stuff there.

Sub moveItOnOut()
If Selection.Information(wdWithInTable) = True Then
' go to the last row
Selection.Move unit:=wdRow, Count:=Selection.Tables(1).Rows.Count
' go to the last cell of that row
Selection.Move unit:=wdCell, Count:=Selection.Tables(1).Columns.Count
' Now move down two lines, beyond the table end
Selection.Move unit:=wdLine, Count:=2
End If
End Sub

Create and publish documentation through multiple channels with Doc-To-Help.
Choose your authoring formats and get any output you may need. Try
Doc-To-Help, now with MS SharePoint integration, free for 30-days.

You are currently subscribed to TECHWR-L as archive -at- web -dot- techwr-l -dot- com -dot-

To unsubscribe send a blank email to
techwr-l-unsubscribe -at- lists -dot- techwr-l -dot- com
or visit

To subscribe, send a blank email to techwr-l-join -at- lists -dot- techwr-l -dot- com

Send administrative questions to admin -at- techwr-l -dot- com -dot- Visit for more resources and info.

Please move off-topic discussions to the Chat list, at:


Getting out of a table in VBA: From: Larry Landis

Previous by Author: RE: Tips on how to talk to SMEs
Next by Author: RE: Getting out of a table in VBA
Previous by Thread: Getting out of a table in VBA
Next by Thread: RE: Getting out of a table in VBA

What this post helpful? Share it with friends and colleagues:

Sponsored Ads