|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
* 呵呵!不好意思!杜先生——你的代码败北了!
* 我决定还是采用我原来的原创《跳过表格只处理文本》代码。
* 杜先生 也不妨测试一下,全部代码如下:(请注意看宏运行时间比较,在处理有表格文档时)
- Sub a计算宏运行所用时间()
- Dim t As Single
- t = Timer
- test '宏名------杜先生 6.39/6.21/6.31 我的代码----1.76/1.76/1.42
- MsgBox "OK!用时 " & Timer - t & " 秒!", vbOKOnly + vbExclamation, "计算宏运行所用时间"
- End Sub
- Sub test_du()
- Dim d As Document, t As Table
- Set d = ActiveDocument
- With d
- For Each t In .Tables
- With t.Range
- .Rows.WrapAroundText = False '取消表格环绕
- .Rows.Alignment = wdAlignRowCenter
- .Font.Name = "仿宋_GB2312"
- .Font.Name = "Times New Roman"
- End With
- Next
- With .Range(0, 0)
- Do While .End < d.Content.End - 1
- If .Information(12) Then
- .Expand 15: .Move
- Else
- With .Paragraphs(1).Range
- .Select
- 正文样式
- If Len(Selection) = 1 And Asc(Selection) = 13 Then .Delete: GoTo skip '分页符后面的回车符删不掉!
- End With
- .Move 4
- End If
- skip:
- Loop
- End With
- End With
- End Sub
- Sub test()
- On Error Resume Next
- Dim doc As Document, t As Table, i As Paragraph, j&, k&, r As Range, v&
- Set doc = ActiveDocument
- If doc.Paragraphs(1).Range.Information(wdWithInTable) = False Then
- Selection.HomeKey unit:=wdStory
- doc.Tables.Add Range:=Selection.Range, NumRows:=1, NumColumns:=1
- v = 1
- End If
- For Each t In doc.Tables
- With t.Range
- .Rows.WrapAroundText = False
- .Rows.Alignment = wdAlignRowCenter
- .Font.Name = "仿宋"
- .Font.Name = "Times New Roman"
- .Previous(unit:=wdParagraph, Count:=1).Characters.Last.InsertBefore Text:="`"
- End With
- Next
- doc.Content.InsertAfter Text:="`"
- k = doc.Tables.Count
- Do
- j = j + 1
- doc.Tables(j).Range.Next(unit:=wdParagraph, Count:=1).Characters(1).Select
- Selection.MoveEndUntil cset:="`", Count:=wdForward
- Selection.MoveEnd unit:=wdCharacter, Count:=2
-
- 正文样式
- Selection.Characters.Last.Previous.Delete
- Set r = Selection.Range
- For Each i In r.Paragraphs
- If Len(i.Range) = 1 And Asc(i.Range) = 13 Then i.Range.Delete
- Next
- r.Select
- Loop Until j = k
- If v = 1 Then doc.Tables(1).Delete
- End Sub
- Sub 正文样式()
- '更新
- With Selection
- .ClearFormatting
- CommandBars.FindControl(ID:=122).Execute
- CommandBars.FindControl(ID:=123).Execute
- With .Font
- .Name = "仿宋_GB2312"
- .Name = "Times New Roman"
- .Size = 16
- .Color = wdColorBlue
- .Kerning = 0
- .DisableCharacterSpaceGrid = True
- End With
- With .ParagraphFormat
- .LineSpacing = LinesToPoints(1.25)
- .CharacterUnitFirstLineIndent = 2
- .AutoAdjustRightIndent = False
- .DisableLineHeightGrid = True
- End With
- End With
- End Sub
复制代码 |
|