Moving a Table in Word Using VBA

Hi,

Brand new programmer here! I'm currently working on a macro in Excel that will open up an MS Word document and input data from Excel.

Part of the data pull from Excel includes a formatted table. I have figured out how to insert the table into MS Word at the correct place in the document using a bookmark, but unfortunately can't figure out how to get the table to center itself. Any suggestions? My bookmark in MS Word is centered but the table is still inserted left justified. Relevant code section is below.

Thanks!

ActiveSheet.Range(table_range).Select
Selection.Copy

With wrdApp
    .Selection.Goto What:=wdGoToBookmark, Name:="Chart"
    .Selection.Paste
    .Visible = True
End With
DC1983Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

GrahamSkanRetiredCommented:
It's not particularly intuitive - the Table object doesn't have a .Left property.
    Dim tbl As Word.Table
    Dim rng As Word.Range
    
    ActiveSheet.Range(table_range).Select
    Selection.Copy

    Set rng = wrdApp.ActiveDocument.Bookmarks("Chart").Range
    rng.Paste
    Set tbl = rng.Tables(1)
    With tbl.Rows
        .RelativeHorizontalPosition = wdRelativeHorizontalPositionMargin
        .HorizontalPosition = wdTableCenter
    End With

Open in new window

0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
DC1983Author Commented:
Code works! Thanks for your heilp
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Programming Languages-Other

From novice to tech pro — start learning today.