当前位置:首页教育技巧word技巧Word技巧大全

怎么设置Word表格的VBA代码

减小字体 增大字体 2025-01-27 10:09:06


今天小编教大家怎么设置Word表格的VBA代码,用得着的朋友可以一起看看。

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

  以上的代码功能为:表格集合中的循环与对单元格边框的设置。

评论评论内容只代表网友观点,与本站立场无关!

   评论摘要(共 0 条,得分 0 分,平均 0 分)

【免责声明】本站信息来自网友投稿及网络整理,内容仅供参考,如果有错误请反馈给我们及时更正,对文中内容的真实性和完整性本站不提供任何保证,不承但任何责任。
版权所有:学窍知识网 Copyright © 2011-2025 www.at317.com All Rights Reserved .