How JustAnswer Works:
  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site.
    Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.
Ask Greg Maxey Your Own Question
Greg Maxey
Greg Maxey, Consultant\Microsoft Word Expert
Category: General
Satisfied Customers: 62
Experience:  Microsoft Word Most Valuable Professional (6 years)
16468162
Type Your Question Here...
Greg Maxey is online now
A new question is answered every 9 seconds

Win 7, Word 2010. I generate Word documents using Author-it,

This answer was rated:

Win 7, Word 2010. I generate Word documents using Author-it, a content management system. The generated documents have many tables. Each time a document is generated, the tables have Cell margin properties that I would like to set to 0. I need a macro that will select all the tables in the doc, and set the cell margins to 0 on top, bottom, left, and right. I can do this manually in the table properties page in the Table Options and Cell Options dialogs.
Can this be accomplished with a macro?
Can you provide such a macro?
Thanks,
Glenn

Glenn,

Try:

Sub ScratchMacro()
Dim oTbl As Word.Table

For Each oTbl In ActiveDocument.Tables

With oTbl

.TopPadding = InchesToPoints(0)

.BottomPadding = InchesToPoints(0)

.LeftPadding = InchesToPoints(0)

.RightPadding = InchesToPoints(0)

End With

Next

End Sub

 

Customer: replied 5 years ago.
Thanks Greg. This is close.

The Table Properties, Table tab, Options dialog indeed shows 0 values in the margins fields.

However, the Table Properties, Cell tab, Options dialog, same as whole table check box is not selected and the margins fields still have values.

Thoughts?

BTW, I love the simplicity of your macro.

Glenn,

Try the following. It loops and sets the table and then loops ans sets each cell in the table. The checkbox "Same as whole table" does not appear to be exposed to the object model. I don't think it can be manipulated with VBA.

Sub ScratchMacro()
Dim oTbl As Word.Table
Dim oCell As Word.Cell
For Each oTbl In ActiveDocument.Tables
With oTbl
.TopPadding = InchesToPoints(0)
.BottomPadding = InchesToPoints(0)
.LeftPadding = InchesToPoints(0)
.RightPadding = InchesToPoints(0)
End With
For Each oCell In oTbl.Range.Cells
With oCell
.TopPadding = InchesToPoints(0)
.BottomPadding = InchesToPoints(0)
.LeftPadding = InchesToPoints(0)
.RightPadding = InchesToPoints(0)
End With
Next oCell
Next oTbl
End Sub

Greg Maxey and 55 other General Specialists are ready to help you
Customer: replied 5 years ago.
That did it, Greg. You're a true VBA master.

Thanks!