|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
对比下这个用时多少:
- Sub test()
- Dim i%, j%, k%, n%, p%, t, temp, arr(1 To 10000, 1 To 3)
- Application.ScreenUpdating = False
- t = Timer
- k = 0
- With ActiveDocument
- n = .Paragraphs.Count '获取文档总段数
- For i = 1 To n
- If Len(.Paragraphs(i).Range.Text) > 1 Then
- For j = i To n
- If Len(.Paragraphs(j).Range.Text) = 1 Then
- k = k + 1
- For p = 1 To Len(.Paragraphs(i).Range.Text)
- If .Paragraphs(i).Range.Characters(p).Text Like "[a-zA-Z]" Then
- arr(k, 1) = UCase(.Paragraphs(i).Range.Characters(p).Text)
- Exit For
- End If
- Next
- arr(k, 2) = i
- arr(k, 3) = j - 1
- Exit For
- End If
- Next
- i = j
- End If
- Next
- For i = 1 To k - 1
- For j = i + 1 To k
- If arr(i, 1) > arr(j, 1) Then
- For p = 1 To 3
- temp = arr(i, p)
- arr(i, p) = arr(j, p)
- arr(j, p) = temp
- Next
- End If
- Next
- Next
- For i = 1 To k '按先后顺序复制到文档最后
- .Range(.Paragraphs(arr(i, 2)).Range.Start, .Paragraphs(arr(i, 3)).Range.End).Select '选中
- Selection.Copy '复制
- .Range.InsertParagraphAfter '在文档后插入一行
- Selection.EndKey Unit:=wdStory '光标移到文档尾
- Selection.Paste '粘贴
- Next
- .Range(.Paragraphs(1).Range.Start, .Paragraphs(n).Range.End).Select '选中原来的内容
- Selection.Delete '删除
- End With
- Application.ScreenUpdating = True
- MsgBox "处理完成!用时:" & Format(Timer - t, "0.000") & "秒!", "64", "温馨提示"
- End Sub
复制代码
|
评分
-
1
查看全部评分
-
|