|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
原帖由 chuhaiou 于 2009-5-23 19:05 发表
我还是想将选择题合并成一个段落...
可试试如下代码。只是要说明一点:如用红色直接标注选项,请只标注字母本身,不要连后面的标点也标注,可以标注多个选项,也可以括号内标注。另外,不保证可准确判断选择题的结束位置,如其后一题答案内容是以A-F开头,则选择题答案可能与其后一题答案内容在同一段落。
Sub test5()
'没有选定内容则对全文档进行处理
Dim oDoc As Document, Doc As Document
Dim myRange As Range
Dim num%, i%, info$, num2%, myend&
On Error Resume Next
Application.ScreenUpdating = False
Set oDoc = ActiveDocument
Set Doc = Documents.Add
oDoc.Activate
Set myRange = IIf(Selection.Type = wdSelectionIP, ActiveDocument.Content, Selection.Range)
myRange.Select
With Selection.Find
.ClearFormatting
.Text = ""
.Font.Color = wdColorRed '答案内容以红色字体标注
.Format = True
.Replacement.ClearFormatting
Do While .Execute
If .Parent.End > myRange.End Then Exit Do
num = Int(Val(.Parent.Paragraphs(1).Range.Text))
Do While num = 0
i = i + 1
num = Int(Val(.Parent.Previous(wdParagraph, i).Text))
If i > 10 Then Exit Do
Loop
If .Parent.Paragraphs(1).Range.End = myend Then
Doc.Content.InsertAfter " "
Else
Doc.Content.InsertAfter vbCrLf & IIf(num = num2, "", num & ".")
End If
Doc.Bookmarks("\endofdoc").Range.FormattedText = .Parent.FormattedText
myend = .Parent.Paragraphs(1).Range.End
num2 = num
i = 0
If .Parent.End = myRange.End Then Exit Do
Loop
End With
With Doc.Content
.Characters.First.Delete
With .Find
.MatchWildcards = True
.Execute "^13 ", replacewith:="^p", Replace:=wdReplaceAll
Do While .Execute("([. ])([A-FA-F]@)[^13 ]", replacewith:="\1\2 ", Replace:=wdReplaceOne)
.Parent.Collapse wdCollapseEnd
Loop
.Parent.WholeStory
Do While .Execute("([. ][A-FA-F]@) ([A-FA-F][^13 ])", replacewith:="\1\2", Replace:=wdReplaceOne)
.Parent.Collapse wdCollapseEnd
Loop
.Parent.WholeStory
.Execute " ^13", replacewith:="^p", Replace:=wdReplaceAll
.Execute "([. ][A-FA-F]@) ([0-9]@.[!A-FA-F])", replacewith:="\1^p\2", Replace:=wdReplaceAll
.Execute "^13{2,}", replacewith:="^p", Replace:=wdReplaceAll
.Font.Color = wdColorRed
With .Replacement.Font
.Color = wdColorAutomatic
.Underline = wdUnderlineNone
.Bold = False
.Italic = False
End With
.Execute "", Format:=True, MatchWildcards:=False, replacewith:="^&", Replace:=wdReplaceAll
End With
End With
Application.ScreenUpdating = True
End Sub,
[ 本帖最后由 sylun 于 2009-5-23 23:40 编辑 ] |
|