Move a table using VBA?

J

Jamie Collins

To move a table manually, I hover over the table, grab the NESW
graphic in the top left corner, drag it to the position desired
position 'by eye' (i.e. right a little) then drop. Now repeat for the
other 40 tables...

Is there any way of doing the above using VBA? Word.Table has no Left
property of its own but does it implement an interface with a Left
property?

Am I missing a trick with styles or similar? The tables were created
from the same empty table copied+pasted as many times as required.

TIA,
Jamie.

--
 
J

Jay Freedman

Jamie said:
To move a table manually, I hover over the table, grab the NESW
graphic in the top left corner, drag it to the position desired
position 'by eye' (i.e. right a little) then drop. Now repeat for the
other 40 tables...

Is there any way of doing the above using VBA? Word.Table has no Left
property of its own but does it implement an interface with a Left
property?

Am I missing a trick with styles or similar? The tables were created
from the same empty table copied+pasted as many times as required.

TIA,
Jamie.

When you drag a table to a new position, that's equivalent to going to the
Table > Table Properties dialog, setting the wrapping to Around, clicking
the Position button, and setting the horiontal and/or vertical position
numbers to something other than the defaults.

Recording the use of the dialog -- and then cleaning up the meaningless
garbage that appears because the recorder includes everything in the dialog,
not just what changed -- shows that the positioning elements are members of
the Rows collection, not of the table as a whole. Try this in a sample
document that contains at least one table:

Sub x()
Dim oTbl As Table
Set oTbl = ActiveDocument.Tables(1)
With oTbl.Rows
.WrapAroundText = True
.HorizontalPosition = InchesToPoints(0.75)
.RelativeHorizontalPosition = wdRelativeHorizontalPositionColumn
.VerticalPosition = InchesToPoints(0.6)
.RelativeVerticalPosition = wdRelativeVerticalPositionMargin
End With
End Sub


--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the newsgroup so
all may benefit.
 
J

Jamie Collins

When you drag a table to a new position, that's equivalent to going to the
Table > Table Properties dialog, setting the wrapping to Around, clicking
the Position button, and setting the horiontal and/or vertical position
numbers to something other than the defaults.

Recording the use of the dialog

Thanks. I hadn't realized that changing the table properties to
'Around' via the dialog was key. I tried this and got some strange
results in that some of the tables were overlaid on each other. No
doubt I could have got this to work eventually...

I then had a brainwave: increase the margins for the pages with the
tables :)

Jamie.

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top