vbams-wordword-2007

VBA code to set all word table's left cell margin to a particular value


I have spent all day trying to find a solution to this issue that I thought would be simple but is proving to be very difficult.

I want to create a macro that will go through all the tables in a Word 2007 document and make sure that the left cell padding (cell margin) is set to 0 instead of the default of .08. The tables have no borders and I want the text inside the tables to be flush with the corresponding paragraphs.

I want this standard for all tables regardless of the table style. There are different tables styles in the document that are formatted in Excel and copied and pasted into the document. Since the persons performing this task sometimes forgets to manually change these cell margins until just before the printed document is going out the door, I would like to automate this step if possible.

BTW, I have seen code that supposedly works if you have the cursor in the table, but that is not what I am looking for. I want to perform this on all tables with one macro run, regardless of where the cursor is.

Many Thanks


Solution

  • The following code was provided to me by Greg Maxey from the Microsoft community.

    Dim oTbl As Word.Table
        For Each oTbl In ActiveDocument.Tables
        oTbl.LeftPadding = 0
    Next 
    

    His Word tips webisite is at:

    http://gregmaxey.mvps.org/word_tips.html