0

I've spent a bunch of time trying to figure out how to get this done but to no avail.

We populate a new word doc based on a template using data from Excel. Excel VBA script gets the data and pastes it into the Word doc at the indicated bookmarks. This works great.

However, when I try to align a column that already exists in the table, it throws an error. I've tried other variants but am just shooting in the dark.

The code compiles without error.

' This code runs fine
ActiveDocument.Tables(1).AutoFitBehavior wdAutoFitWindow
ActiveDocument.Tables(1).PreferredWidthType = wdPreferredWidthPercent
ActiveDocument.Tables(1).PreferredWidth = 100

ActiveDocument.Tables(1).Columns(2).Select

' I get an error "438 - Object Doesn't support this property or method"
Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter

Any thoughts are appreciated.

Doug

1 Answer 1

0

Try something like this:

Dim c As Cell, t as Table
Set t = ActiveDocument.Tables(1) 
With t.Columns(2) 
    For Each c In .Cells 
        c.Range.ParagraphFormat.Alignment = wdAlignParagraphCenter 
    Next c 
End With 
1
  • Solved my challenge perfectly. I was hoping for a column-wise solution but if I have to do it cell-by-cell, so be it. Mar 5, 2014 at 20:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.