请参: '* +++++++++++++++++++++++++++++
'* Created By 守柔(ShouRou)@ExcelHome 2005-3-13 6:54:29
'仅测试于System: Windows NT Word: 10.0 Language: 2052
'^The Code CopyIn [ThisDocument-ThisDocument]^'
'* -----------------------------Sub SetFormat()
Dim i As Paragraph, aChar As Range, MyRange As Range
On Error Resume Next
Application.ScreenUpdating = False
With ActiveDocument
For Each i In .Paragraphs '段落中循环
If VBA.InStr(i.Range, " ") = 1 Then '首字包含部分空格
Set MyRange = .Range(i.Range.Start + 16, i.Range.End - 1)
'对应于该段落的前一个段落,预置下划线以加快运行速度
.Range(MyRange.Start - 77, MyRange.End - 77).Underline = True
'对应于该段落的前两个段落,预置下划线以加快运行速度
.Range(MyRange.Start - 154, MyRange.End - 154).Underline = True
For Each aChar In MyRange.Characters
If aChar <> "*" Then '如果不是*则去除下划线
.Range(aChar.Start - 77, aChar.End - 77).Underline = False
.Range(aChar.Start - 154, aChar.End - 154).Underline = False
End If
Next
End If
Next
End With
Application.ScreenUpdating = True '恢复屏幕更新
Call GetAllGone
End Sub
'----------------------
Sub GetAllGone()
Dim i As Paragraph, MyDoc As Document, MyRange As Range, DocRange As Range
On Error Resume Next
Application.ScreenUpdating = False
Set MyDoc = Documents.Add '新建一个空白文档
Selection.InsertAfter Chr(13) '插入段落标记(此文档中现有两个段落)
With ThisDocument '本文档
For Each i In .Paragraphs '本文档段落中循环
If VBA.InStr(i.Range, "Axxxxx0") = 1 Then
Set MyRange = .Range(i.Range.Start + 16, i.Range.End - 1)
MyRange.Copy '复制相应区域以便保留格式
Set DocRange = MyDoc.Paragraphs(1).Range
'在MyDoc的第一个段落标记前一个位置粘贴
MyDoc.Range(DocRange.End - 1, DocRange.End - 1).Paste
ElseIf VBA.InStr(i.Range, "Bxxxxx1") = 1 Then
Set MyRange = .Range(i.Range.Start + 16, i.Range.End - 1)
MyRange.Copy '复制相应区域以便保留格式
Set DocRange = MyDoc.Paragraphs(2).Range
'在MyDoc的第一个段落标记前一个位置粘贴
MyDoc.Range(DocRange.End - 1, DocRange.End - 1).Paste
End If
Next
End With
With MyDoc '实际应用中,会有空格产生,替换
.Content.Find.Execute findtext:=" ", Replacewith:="", Replace:=wdReplaceAll
'插入一个段落
.Paragraphs(1).Range.InsertBefore "Axxxxx0:" & Chr(13)
'插入一个段落
.Paragraphs(3).Range.InsertBefore "Bxxxxx1:" & Chr(13)
'保存该文档
.SaveAs "New-" & ThisDocument.Name
End With
Application.ScreenUpdating = True '恢复屏幕更新
End Sub
'---------------------- |