|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
* 楼主,请试试我在整个宇宙独家原创的 VBA 宏代码:(如果表格太多,请备份文档后,耐心等待)
- Sub 循环遍历所有表格及单元格_财会表格()
- '功能:光标在表格中处理当前表格;否则处理所有表格!
- Dim t As Table, i As Long, c As Cell, r As Range
- If Selection.Information(wdWithInTable) = True Then i = 1
- For Each t In ActiveDocument.Tables
- If i = 1 Then Set t = Selection.Tables(1)
- For Each c In t.Range.Cells
- Set r = c.Range
- With r
- If Asc(r) < 0 Then
- .Font.Color = wdColorPink '粉红
- .ParagraphFormat.Alignment = wdAlignParagraphLeft
- .ParagraphFormat.CharacterUnitLeftIndent = 0.5
- If r Like "*减:*" Then
- .Select
- CommandBars.FindControl(ID:=122).Execute
- CommandBars.FindControl(ID:=123).Execute
- .InsertBefore Text:=Chr(-24159)
- ' End If
- End If
- ElseIf Asc(r) > 0 Then
- .Font.Color = wdColorBlue '蓝色
- .ParagraphFormat.Alignment = wdAlignParagraphRight
- .ParagraphFormat.CharacterUnitRightIndent = 0.5
- End If
-
- '首行加粗
- With t.Rows(1).Range
- With .Font
- .Name = "黑体"
- .Bold = True
- .Color = wdColorRed '红色
- End With
- With .ParagraphFormat
- .Alignment = wdAlignParagraphCenter
- .LeftIndent = CentimetersToPoints(0)
- .CharacterUnitLeftIndent = 0
- End With
- .HighlightColorIndex = wdYellow '突出显示/黄色
- End With
-
- '末行加粗
- With t.Rows(t.Rows.Count).Range
- With .Font
- .NameFarEast = "黑体"
- .NameAscii = "宋体"
- .Bold = True
- .Color = wdColorAutomatic '自动色
- End With
- With .Cells(1).Range
- .Font.Color = wdColorRed '红色
- With .ParagraphFormat
- .Alignment = wdAlignParagraphCenter
- .LeftIndent = CentimetersToPoints(0)
- .CharacterUnitLeftIndent = 0
- End With
- End With
- .HighlightColorIndex = wdYellow '突出显示/黄色
- End With
- End With
- Next
- If i = 1 Then Exit For
- Next
- MsgBox "处理完毕!!!!!!!!!!!!" & vbCr & vbCr & _
- "*** 如果想打印,只须<全选>,再点击<突出显示:无>即可!" & vbCr & _
- "*** 如果想打印,只须<全选>,再点击<自动色>即可!" & vbCr & _
- "*** 注释语句可以删除,或注释掉!" & vbCr & _
- "*** 特殊功能:光标在表格中处理当前表格;否则处理所有表格!", vbOKOnly + vbExclamation
- End Sub
复制代码 |
|