Nudging a Table

by Allen Wyatt
(last updated May 1, 2020)

1

Ray wonders if there is a way to move an entire Word table vertically, pixel by pixel. Everything he has read indicates that grabbing it and holding the Alt key will allow for that, but it does not work smoothly.

I'm not sure where Ray has been reading, but the Alt key does not allow for nudging tables. In fact, it doesn't seem to work for table movement at all, with one exception—if you press Shift+Alt and then use the up or down arrow keys, the table is moved up or down an entire paragraph in your document.

Other keystroke combinations don't work either. You would think that nudging tables would work as it does for other objects within a document—you select the object and then use the arrow keys to give the nudge. However, it doesn't work with tables at all. If you select the table and then press the up or down arrow keys, then Word deselects the table and moves the insertion point either above or below the table in the document.

There are a couple of workarounds you can use, however. First, you could adjust how you put your tables in the document. Simply put them within a text box, and then you can use the arrow keys to nudge the text box. (You can also format the border on the text box so it doesn't show.)

Another workaround is to use a macro to do the movement. The following macro will move the table a single pixel up:

Sub MoveTableUp1()
' set pxl to the number of pixels to move: positive for down and
'   negative for up
    Const pxl As Single = -1

    If Not Selection.Information(wdWithInTable) Then Exit Sub
    With Selection.Tables(1)
        .Rows.VerticalPosition = .Rows.VerticalPosition + PixelsToPoints(pxl)
    End With
End Sub

All you need to do is make sure that the insertion point is within the table you want to nudge. If you want to move the table down instead of up, simply change the definition of the pxl constant to be a positive 1 instead of a negative 1.

There is something else you should note about this macro—it may mess up your document layout. You see, the VerticalPosition property is only effective if your table is configured to allow text to wrap around it. (This is configured in the Table Wrapping area of the Table Properties dialog box.) Recognizing this, when you use the macro to adjust the VerticalPosition property, it automatically changes the table from "none" to "around." This, obviously, could affect the page layout if you didn't previously have wrapping turned on and the table is narrower than your text area.

There is another potential "gotcha" here, as well. You might think that you can adjust the horizontal position of the table by changing the VerticalPosition property in the above macro to HorizontalPosition. This seems logical, but how it works in the macro may throw you for a loop. Where adjusting the VerticalPosition property will change the table wrapping from "none" to "around," adjusting the HorizontalPosition property will not. Instead, on some versions of Word, it will give you an error.

The safest way to deal with all of these quirks is to adjust the macro to make sure that it only adjusts a table if its wrapping property is set to True, in this manner:

Sub MoveTableUp2()
    Dim sTemp As String

' set pxl to the number of pixels to move: positive for down and
'   negative for up
    Const pxl As Single = -1

    sTemp = ""
    If Selection.Information(wdWithInTable) Then
        With Selection.Tables(1).Rows
            If .WrapAroundText Then
                .VerticalPosition = .VerticalPosition + PixelsToPoints(pxl)
            Else
                sTemp = "Table is inline. No action taken."
            End If
        End With
    Else
        sTemp = "The insertion point is not within a table. No action taken."
    End If
    If sTemp > "" Then MsgBox sTemp
End Sub

This variation of the macro also includes a bit more feedback for the user so that if no action is taken, the user is told why this is the case.

If you prefer, you can move the table a point (1/72 of an inch) at a time. Here's the version of the macro that could handle this movement:

Sub MoveTableUp3()
    Dim sTemp As String

' set pt to the number of points to move: positive for down and
'   negative for up
    Const pt As Single = -1

    sTemp = ""
    If Selection.Information(wdWithInTable) Then
        With Selection.Tables(1).Rows
            If .WrapAroundText Then
                .VerticalPosition = .VerticalPosition + pt
            Else
                sTemp = "Table is inline. No action taken."
            End If
        End With
    Else
        sTemp = "The insertion point is not within a table. No action taken."
    End If
    If sTemp > "" Then MsgBox sTemp
End Sub

As already discussed, nudging the table horizontally instead of vertically is simply of matter of using the HorizontalPosition property with the Rows object rather than the VerticalPosition property. Remember, though, the caveats discussed, as well, as to how the HorizontalPosition property differs in use from the VerticalPosition property. With this in mind, you could rather easily create four versions of your macro (for each of the four directions you might want to nudge your table) and then assign shortcut keys to the macros.

Note:

If you would like to know how to use the macros described on this page (or on any other page on the WordTips sites), I've prepared a special page that includes helpful information. Click here to open that special page in a new browser tab.

WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (12136) applies to Microsoft Word 2007, 2010, 2013, 2016, 2019, and Word in Office 365.

Author Bio

Allen Wyatt

With more than 50 non-fiction books and numerous magazine articles to his credit, Allen Wyatt is an internationally recognized author. He is president of Sharon Parq Associates, a computer and publishing services company. ...

MORE FROM ALLEN

Understanding Views

Need to display your worksheet in different ways? A quick way to do this is to create views, as described in this tip.

Discover More

Cannot Add Words to Dictionary

We all run across words that are spelled correctly, but that Word isn't aware of. The solution is to add those words to ...

Discover More

Determining the Day of the Month

When writing macros, you may need to know which day of the month a particular date represents. Here's how to use the Day ...

Discover More

Comprehensive VBA Guide Visual Basic for Applications (VBA) is the language used for writing macros in all Office programs. This complete guide shows both professionals and novices how to master VBA in order to customize the entire Office suite for their needs. Check out Mastering VBA for Office 2010 today!

More WordTips (ribbon)

Changing Table Cell Text Direction

When creating a table, you can turn the orientation of the text, within a cell, by ninety degrees in either direction ...

Discover More

Hiding Table Rows on a Printout

When you work with tables in your document, you may want to hide some of rows in those tables so that they don't print ...

Discover More

Drop Shadows for Tables

When adding borders and shading to a document's elements, Word allows you to quickly add drop shadows to paragraphs, text ...

Discover More
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

View most recent newsletter.

Comments

If you would like to add an image to your comment (not an avatar, but an image to help in making the point of your comment), include the characters [{fig}] in your comment text. You’ll be prompted to upload your image when you submit the comment. Maximum image size is 6Mpixels. Images larger than 600px wide or 1000px tall will be reduced. Up to three images may be included in a comment. All images are subject to review. Commenting privileges may be curtailed if inappropriate images are posted.

What is 4 + 0?

2018-08-11 07:25:37

Al Wilson

Sorry, but for me this macro does not work. Well, at least works in a strange way. The Macro for moving Up and Down actually move my table left and right, whereas my modified version using HosizontalPosition causes an error 9118 Parameter value was out of accepted range. This was when using pxl parameter as either 1 or -1. Basically no change to the macro other than changing VerticalPosition to HorizontalPosition.

Can't understand the issue unless it thinks my document is in Landscape mode (It is in portrait) but that would not explain the 9118 error.
I assume HorizontalPosition can be incremented or decremented by a Single of either 1 or -1?

Edit. Up and Down work correctly but using HorizontalPosition causes the error 9118. I am using Word 2016.


This Site

Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.

Newest Tips
Subscribe

FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."

(Your e-mail address is not shared with anyone, ever.)

View the most recent newsletter.