设置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
以上的代码功能为:表格集合中的循环与对单元格边框的设置。
您可能感兴趣的文章
- 03-24word里代码对齐快捷键是什么意思
- 03-24word在兼容模式是什么意思
- 03-24word文档字为什么不能前移
- 03-24word文档为什么不能接受修订
- 03-24word中方正小标宋什么意思
- 03-24word为什么会保存文件错误报告
- 03-24cad图为什么插入不到word中,cad图怎么插到word中
- 03-24word表格内为什么不能另起一行,word表格内怎么另起一行
- 03-24为什么word里插不进去页码,word怎么插页码?
- 03-24为什么wps word页面绿色变不回来


阅读排行
推荐教程
- 07-012025最新office2010永久激活码免费分享,附office 2010激活工具
- 07-01怎么免费获取2025最新office2016专业增强版永久激活密钥/序列号
- 07-01office365怎么永久激活?2025.5最新office,office365序列号推荐
- 06-25office2021年最新永久有效正版激活密钥免费分享
- 06-13Office 2024激活工具,2025年Office2024激活工具及激活密钥分享
- 05-12Microsoft office2019产品激活密钥(100%永久激活)
- 07-01office2021专业增强版2021激活密钥2023密钥永久激活 万能office202
- 06-17经验分享Win11激活密钥怎么获取(win11专业版激活密钥)
- 07-01office 2021激活码/序列号推荐,office2021附激活工具
- 06-25Office2021激活密钥永久最新分享




