vba-word第一讲(修改word文档中表格的样式及字体)

Sub EXCLE()
'功能:光标在表格中处理当前表格;否则处理所有表格!
'Application.ScreenUpdating = False '关闭屏幕刷新
'Application.DisplayAlerts = False '关闭提示
'On Error Resume Next '忽略错误
'***************************************************************************
Dim mytable As Table, i As Long
If Selection.Information(wdWithInTable) = True Then i = 1
For Each mytable In ActiveDocument.Tables
If i = 1 Then Set mytable = Selection.Tables(1)
With mytable
With .Rows
.WrapAroundText = False '取消文字环绕
.Alignment = wdAlignRowCenter '表水平居中 wdAlignRowLeft '左对齐
.AllowBreakAcrossPages = False '不允许行断页
.HeightRule = wdRowHeightExactly '行高设为最小值 wdRowHeightAuto '行高设为自动
.Height = CentimetersToPoints(0) '上面缩进量为0
.LeftIndent = CentimetersToPoints(0) '左面缩进量为0
End With
With .Range
With .Font '字体格式
.Name = "宋体"
.Name = "Times New Roman"
.Color = wdColorAutomatic '自动字体颜色
.Size = 9
.Kerning = 0
.DisableCharacterSpaceGrid = True
End With

With .ParagraphFormat '段落格式
.CharacterUnitFirstLineIndent = 0 '取消首行缩进
.FirstLineIndent = CentimetersToPoints(0) '取消首行缩进
.Alignment = wdAlignParagraphCenter '单元格水平居中
.AutoAdjustRightIndent = False
.DisableLineHeightGrid = True

End With


.Cells.VerticalAlignment = wdCellAlignVerticalCenter '单元格垂直居中

End With


End With

If i = 1 Then Exit For
Next
'***************************************************************************
Err.Clear: On Error GoTo 0 '恢复错误捕捉
Application.DisplayAlerts = True '开启提示
Application.ScreenUpdating = True '开启屏幕刷新

End Sub

posted @   0和1在打架  阅读(1662)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 上周热点回顾(3.3-3.9)
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具
点击右上角即可分享
微信分享提示