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
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· winform 绘制太阳,地球,月球 运作规律
· 超详细:普通电脑也行Windows部署deepseek R1训练数据并当服务器共享给他人
· 上周热点回顾(3.3-3.9)
· AI 智能体引爆开源社区「GitHub 热点速览」
· 写一个简单的SQL生成工具