To set VBA code for a Word table

Source: Internet
Author: User

The VBA code sets the Word table properties.

Dim I as Table, N as Integer

On error Resume Next ' Ignore error

application.screenupdating = False ' Turn off screen update

For all I in activedocument.tables ' loops in the table

With I

. style = List Type 4 ' Sets all tables to list Type 4 '

With. Borders ' border

. InsideLineStyle = wdLineStyleSingle ' Set internal border line

End With

With. Rows (1). Borders (Wdborderbottom) ' The bottom border of the first row

. LineStyle = wdLineStyleDouble ' double line style

. LineWidth = wdlinewidth050pt

. Color = wdcolorautomatic

End With

If. Rows.Count > 1 Then ' If the number of table rows is greater than 1

If Len (. Cell (2, 1). Range) <= 2 Then ' If the first column of the second row is not empty

With. Rows (2). Shading ' Set shading

. Texture = Wdtexturenone ' bottomless shading

. ForegroundPatternColor = wdcolorautomatic

. BackgroundPatternColor = wdColorGray125

End With

End If

End If

For N = 2 to. Columns.count ' from the second column to the last column

. Columns (N). Select ' cell alignment centered in middle

Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter

Selection.Cells.VerticalAlignment = Wdcellalignverticalcenter

Next N

End With

Next I

application.screenupdating = True

The above code functions are: loops in the table collection and settings for the cell borders.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.