|
原帖由 chuhaiou 于 2009-5-22 23:28 发表
生成的答案最好是:所有选择题作一个段落,填空题一题一个段落,答案中若有嵌入式图片也能兼顾!
第一个问题主要是如何判断当前匹配内容是不是属于选择题,不同的试卷会有不同的排版方式,估计不好用统一的标准判断,故从略,在生成的文档中用查找替换手工处理应很方便。
至于第二个问题,因前面的程序只获取相关文本,而不是带格式内容。要获取带格式内容,可试试如下代码,但要注意此时图片所在字符位置的字体颜色设置也应为红色:
Sub test4()
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
.Font.Color = wdColorRed
.Format = True
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
.Execute "^p ", replacewith:="^p", Replace:=wdReplaceAll
.Execute "^p^p", replacewith:="^p", Replace:=wdReplaceAll
.Font.Color = wdColorRed
.Replacement.Font.Color = wdColorAutomatic
.Execute "", Format:=True, replacewith:="^&", Replace:=wdReplaceAll
End With
End With
Application.ScreenUpdating = True
End Sub |
|