|
Sub lkyy()
Dim doc As Document, ph As Paragraph, Pstart As Long
Set doc = ActiveDocument
Selection.HomeKey unit:=wdStory
ReDim br(1 To 1000, 1 To 2)
ReDim cr(1 To 1000, 1 To 2)
'读取【题干】里下划线答案
For Each ph In doc.Paragraphs
If Left(ph.Range, 4) = "【题干】" Then
Pstart = ph.Range.Start
n = n + 1: m = 0
br(n, 1) = n
s = ""
For i = 1 To ph.Range.Characters.Count
If ph.Range.Characters(i) = " " Then
m = m + 1
If m Mod 2 = 0 Then s = s & "|" & doc.Range(k, i + Pstart - 1) '将答案提取
If m Mod 2 = 0 Then a = a + 1: cr(a, 1) = k: cr(a, 2) = i + Pstart - 1 '用于去除下划线的字
k = i + Pstart
End If
Next i
br(n, 2) = Mid(s, 2, 999)
End If
Next ph
'加一段为【答案】
doc.Content.Find.Execute "【解析】", , , , , , , , , "【答案】^p【解析】", 2
n = 0
'插入每题题干的答案
For Each ph In doc.Paragraphs
If Left(ph.Range, 4) = "【答案】" Then
n = n + 1
ph.Range.Characters(Len(ph.Range) - 1).InsertAfter br(n, 2)
End If
Next
'删除下划线的字
For i = a To 1 Step -1
doc.Range(cr(i, 1), cr(i, 2)).Delete
Next
End Sub |
|