|
* 楼主,你好!——建议提供真实附件才好(当然关键信息应当处理一下),请试用下面的宏(因为表格是不规则表格,无法对其进行列宽设置,须自行手动设置列宽。本宏采用默认列宽):
- Sub aaab审计报告()
- '页面设置/默认2.54cm/3.17cm/A4纸张
- Dim s As Section
- For Each s In ActiveDocument.Sections
- With s.PageSetup
- If .Orientation = wdOrientPortrait Then
- .TopMargin = CentimetersToPoints(2.54)
- .BottomMargin = CentimetersToPoints(2.54)
- .LeftMargin = CentimetersToPoints(3.17)
- .RightMargin = CentimetersToPoints(3.17)
- .PageWidth = CentimetersToPoints(21)
- .PageHeight = CentimetersToPoints(29.7)
- Else
- .TopMargin = CentimetersToPoints(2.5)
- .BottomMargin = CentimetersToPoints(2.5)
- .LeftMargin = CentimetersToPoints(2.54)
- .RightMargin = CentimetersToPoints(2.54)
- .PageWidth = CentimetersToPoints(29.7)
- .PageHeight = CentimetersToPoints(21)
- End If
- .HeaderDistance = CentimetersToPoints(1.5)
- .FooterDistance = CentimetersToPoints(1.75)
- End With
- Next
-
-
- '循环遍历所有表格
- Dim t As Table, m&, h&, i&
- For Each t In ActiveDocument.Tables
- With t
- '取消文字环绕
- With .Rows
- .WrapAroundText = False
- .Alignment = wdAlignRowLeft
- .LeftIndent = CentimetersToPoints(0)
- End With
- '默认单元格边距
- .LeftPadding = CentimetersToPoints(0.19)
- .RightPadding = CentimetersToPoints(0.19)
-
- '根据内容/窗口扩展表格
- .AutoFitBehavior (wdAutoFitContent)
- .Select
- .AutoFitBehavior (wdAutoFitWindow)
- '行高最小值
- With .Rows
- .HeightRule = wdRowHeightAtLeast
- .Height = CentimetersToPoints(0.6)
- End With
-
- '清除格式/设置字体段落格式
- Selection.ClearFormatting
- With .Range
- With .Font
- .NameFarEast = "宋体"
- .NameAscii = "Times New Roman"
- .Color = wdColorBlue '蓝色(本行代码可删除)
- .Kerning = 0
- .DisableCharacterSpaceGrid = True
- End With
- With .ParagraphFormat
- .Space1
- .Alignment = wdAlignParagraphCenter
- .AutoAdjustRightIndent = False
- .DisableLineHeightGrid = True
- End With
- .Cells.VerticalAlignment = wdCellAlignVerticalCenter
- End With
-
- '''选定第 6 单元格
- .Range.Cells(6).Select
- m = Selection.Information(wdEndOfRangeRowNumber)
- h = .Range.Information(wdMaximumNumberOfRows)
- Selection.MoveDown Unit:=wdLine, Count:=h - m, Extend:=wdExtend
- Selection.ParagraphFormat.Alignment = wdAlignParagraphLeft
-
- '''选定第 7 单元格
- .Range.Cells(7).Select
- m = Selection.Information(wdEndOfRangeRowNumber)
- h = .Range.Information(wdMaximumNumberOfRows)
- Selection.MoveDown Unit:=wdLine, Count:=h - m, Extend:=wdExtend
- Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
-
- '''选定第 8 单元格
- .Range.Cells(8).Select
- m = Selection.Information(wdEndOfRangeRowNumber)
- h = .Range.Information(wdMaximumNumberOfRows)
- Selection.MoveDown Unit:=wdLine, Count:=h - m, Extend:=wdExtend
- Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
-
- '''选定第 9 单元格
- .Range.Cells(9).Select
- m = Selection.Information(wdEndOfRangeRowNumber)
- h = .Range.Information(wdMaximumNumberOfRows)
- Selection.MoveDown Unit:=wdLine, Count:=h - m, Extend:=wdExtend
- Selection.ParagraphFormat.Alignment = wdAlignParagraphRight
-
- '''选定第 1 至第 5 单元格
- With .Range
- i = 0
- Do
- i = i + 1
- .Cells(i).Range.Font.NameFarEast = "黑体"
- .Cells(i).Range.Bold = True
- .Cells(i).Range.Font.Color = wdColorRed '红色(本行代码可删除)
- Loop Until i = 5
- End With
-
- '合计单元格
- With .Range.Cells(34).Range
- .Font.NameFarEast = "黑体"
- .Font.Bold = True
- .Font.Color = wdColorPink
- .ParagraphFormat.Alignment = wdAlignParagraphCenter
- End With
- End With
- Next
-
- Selection.HomeKey 6
-
- MsgBox "处理完毕!!!!!!!!!!", 0 + 48, "审计报告"
- End Sub
复制代码 |
|