|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
本帖最后由 413191246se 于 2012-4-23 17:33 编辑
[code=vb]Sub 表格处理()
' 若光标在表格内则处理光标所在表格;否则将处理所有表格(仅限规则表格!)
On Error Resume Next
Dim i As Long
i = ActiveDocument.Tables.Count
If i = 0 Then MsgBox "当前文档无表格!", vbOKOnly + vbCritical, "表格处理": Exit Sub
Dim a As Long, b As Long, c As String, h As String, s As String, t As Table, n As Long
c = MsgBox("是:自动 否:自定义 取消:放弃", vbYesNoCancel + vbExclamation, "表格处理")
If c = vbYes Then
h = 0.9
s = 12
a = 1
b = 1
ElseIf c = vbNo Then
h = InputBox("请输入表格行高值:(0.7-1.2 厘米比较美观)", "表格处理", "0.9")
If h = "" Then Exit Sub
s = InputBox("请输入表格内文字字号:(比正文小半号比较美观)" & vbCr & "三号/16磅,小三/15磅,四号/14磅,小四/12磅,五号/10.5磅", "表格处理", "12")
If s = "" Then Exit Sub
If MsgBox("根据内容调整表格吗?", vbYesNo + vbExclamation, "自动调整") = vbYes Then a = 1
If MsgBox("所有表格表头加粗吗?", vbYesNo + vbExclamation, "表头加粗") = vbYes Then b = 1
Else
Exit Sub
End If
If Selection.Information(wdWithInTable) = True Then Selection.Tables(1).Select: n = 1
For Each t In ActiveDocument.Tables
If n = 1 Then Set t = Selection.Tables(1) Else t.Select
t.Range.Font.Color = wdColorBlue
' 表格标准化
With t
With .Rows
.WrapAroundText = False
.Alignment = wdAlignRowLeft
.HeightRule = wdRowHeightAtLeast
.Height = CentimetersToPoints(h)
End With
.AutoFitBehavior (wdAutoFitWindow)
.AutoFitBehavior (wdAutoFitWindow)
With .Range
With .Cells
.DistributeWidth
.VerticalAlignment = wdCellAlignVerticalCenter
End With
.Font.Size = s
With .ParagraphFormat
.Alignment = wdAlignParagraphCenter
.CharacterUnitFirstLineIndent = 0
.FirstLineIndent = CentimetersToPoints(0)
.Space1
End With
End With
.Shading.BackgroundPatternColor = wdColorAutomatic
' 根据内容调整表格
If a = 1 Then
.AutoFitBehavior (wdAutoFitContent)
.AutoFitBehavior (wdAutoFitContent)
End If
.Select
.AutoFitBehavior (wdAutoFitWindow)
.AutoFitBehavior (wdAutoFitWindow)
' 表头加粗
If b = 1 Then
With .Rows(1).Range.Font
.Name = "黑体"
.Name = "Times New Roman"
.Bold = True
.Color = wdColorRed
End With
End If
End With
Next
If n <> 1 Then Selection.MoveLeft Unit:=wdCharacter, Count:=1
End Sub[/code]
|
|