Dzwebs.Net

撰写电脑技术杂文十余年

WORD篇VBA用循环设置表格集合、对表格边框的设置

Admin | 2011-4-28 9:35:37 | 被阅次数 | 11142

温馨提示!

如果未能解决您的问题,请点击搜索;登陆可复制文章,点击登陆

   如下的VBA代码功能,是用循环来操作WORD中的表格集合、设置表格的边框等属性。

    Dim i As Table, N As Integer

    On Error Resume Next    ’忽略错误

    Application.ScreenUpdating = False    ’关闭屏幕更新

    For Each i In ActiveDocument.Tables    ’在表格中循环

        With i

            .Style = "列表型 4"    ’将所有表格设置为"列表型4"的样式

            With .Borders    ‘边框

                .InsideLineStyle = wdLineStyleSingle    ’设置内部边框线条

            End With

            With .Rows(1).Borders(wdBorderBottom)    ‘第一行的底边框

                .LineStyle = wdLineStyleDouble    ‘双线型

                .LineWidth = wdLineWidth050pt

                .Color = wdColorAutomatic

            End With

            If .Rows.Count > 1 Then    ’ 如果表格行数大于1

                If Len(.Cell(2, 1).Range) <= 2 Then    ’如果第二行第一列不为空

                    With .Rows(2).Shading    ’设置底纹

                        .Texture = wdTextureNone    ’无底底纹

                        .ForegroundPatternColor = wdColorAutomatic

                        .BackgroundPatternColor = wdColorGray125

                    End With

                End If

            End If

            For N = 2 To .Columns.Count    ’从第二列到最后一列

                .Columns(N).Select    ’单元格对齐方式为中部居中

                Selection.ParagraphFormat.Alignment = wdAlignParagraphCenter

                Selection.Cells.VerticalAlignment = wdCellAlignVerticalCenter

            Next N

        End With

    Next i

    Application.ScreenUpdating = True

End Sub


该杂文来自: Word杂文

上一篇:Word排序中文的方法

下一篇:Word表格线条加粗、线条线型、颜色等的设置

网站备案号:

网站备案号:滇ICP备11001339号-7

版权属性:

Copyright 2007-2021-forever Inc. all Rights Reserved.

联系方式:

Email:dzwebs@126.com QQ:83539231 访问统计