Learn how to a build a cloud-first strategyRegister Now


Customize Cell Padding in Word Tables

Posted on 2009-05-02
Medium Priority
Last Modified: 2012-05-06
Dear Experts:

I got a word 2003 document in which all the tables do not have any left or right cell padding.
I tried to customize the left and right cell padding of a selected Word table with the following code.
But nothing happens. The left and right cell padding remain at 0 cm. Only the first part of the code seems to work (but this has got no effect on the left and right cell padding), the second part starting with 'With Selection.Cells(1) ... obviously has got no effect whatsoever. Is this a bug?

Help is much appreciated. Thank you very much in advance. Regards, Andreas

Sub CustomizeCellPadding()
(PART 1 of the code)
With Selection.Tables(1)
        .TopPadding = CentimetersToPoints(0)
        .BottomPadding = CentimetersToPoints(0)
        .LeftPadding = CentimetersToPoints(0.2)
        .RightPadding = CentimetersToPoints(0.2)
     End With
(PART 2 of the code)  
    With Selection.Cells(1)
        .TopPadding = CentimetersToPoints(0)
        .BottomPadding = CentimetersToPoints(0)
        .LeftPadding = CentimetersToPoints(0.2)
        .RightPadding = CentimetersToPoints(0.2)
        .WordWrap = True
        .FitText = False
    End With
End Sub

Open in new window

Question by:AndreasHermle
  • 2

Expert Comment

ID: 24286621
I don't understand why you can't just highlight the whole table and then go to table properties > cell tab > Options button > and set margins for the cells right and left there.  

If you just need the margin on the right and left side of the whole table just set a right margin for the cells in the right column and a left margin for the cells in the left column, ect.

Author Comment

ID: 24287964
Hi stiffstock,  
ok,  I am  fully aware how to set the margins by means of the table properties menu.But I would like to alter these settings by just pressing a macro button for this purpose on a customized tool bar.  

Regards, Andreas

Accepted Solution

AndreasHermle earned 0 total points
ID: 24290267
Dear Stiffstock,

found out myself how  to  solve my problem. Thank you anyway. Regards, Andreas
Sub TblCellPadding()
Dim myCell As cell
Dim myRow As row
Dim myTable As table
If Not Selection.Information(wdWithInTable) Then
    MsgBox "The code will only be effected, if" & _
    "the cursor is inside the table!", _
     vbOKOnly + vbCritical, "Customize Cell Padding of selected tbl"
     Exit Sub
End If
Set myTable = Selection.Tables(1)
For Each myRow In myTable.rows
For Each myCell In myRow.Cells
myCell.TopPadding = CentimetersToPoints(0)
myCell.BottomPadding = CentimetersToPoints(0)
myCell.LeftPadding = CentimetersToPoints(0.19)
myCell.RightPadding = CentimetersToPoints(0.19)
End Sub

Open in new window


Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft Word is a program we have all encountered at some point, but very few of us have dug deep into its full scope of features, let alone customized it to suit our needs. Luckily making the ribbon (aka toolbar, first introduced in Word 2007) wo…
This article describes how to use the Send to Mail Recipient command. The instructions apply generally to Office 2007 and later versions, but Microsoft® Word 2013 was used for the specific steps and figures.  What is Send to Mail Recipient? Send…
In this video, we show how to convert an image-only PDF file into a PDF Searchable Image file, that is, a file with both the image (typically from scanning) and text, which is created in an automated fashion with Optical Character Recognition (OCR) …
This video shows where to find templates, what they are used for, and how to create and save a custom template using Microsoft Word.
Suggested Courses

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question