|
本帖最后由 kqbt 于 2015-11-7 11:23 编辑
还是分为两个过程吧:
- Sub 整理题号及答案()
- Dim wRng As Range, aStr As String
- Dim cNum As Integer
- Set wRng = ActiveDocument.Content
- With wRng
- .Font.Size = 10.5
- With .Find
- .ClearFormatting
- .Replacement.ClearFormatting
- .Execute "^m", , , False, , , , , , "^p", wdReplaceAll
- .Execute "^b", , , False, , , , , , "^p", wdReplaceAll
- .Execute "[^13 ^32^s^t]@([B-D].)", , True, , , , , , , "^p\1", wdReplaceAll
- .Execute "([!::])([A-D]@)([!.]*)([0-9]@.)", , , True, , , , , , "\1\3答案:\2^p\4", wdReplaceAll
- .Execute "[^11^13]{1,}", , , True, , , , , , "^p", wdReplaceAll
- cNum = 1
- Do While .Execute("^13[0-9]@.", , , True)
- If wRng <> Chr(13) & cNum & "." Then
- wRng.Text = Replace(wRng, Mid(wRng, 2, Len(wRng) - 2), cNum)
- End If
- cNum = cNum + 1
- Loop
- wRng.SetRange wRng.End, ActiveDocument.Content.End
- If .Execute("[!::][A-D]@[!.]", , , True, , , True) Then
- aStr = Mid(wRng, 2, Len(wRng) - 2)
- wRng.Delete
- ActiveDocument.Content.InsertAfter "答案:" & aStr
- End If
- End With
- End With
- End Sub
复制代码- Sub 提取答案()
- Dim wRng As Range, nRng As Range
- Dim cNum As Integer, aStr As String
- cNum = 1
- Set wRng = ActiveDocument.Content
- With wRng.Find
- .ClearFormatting
- .Replacement.ClearFormatting
- Do While .Execute(Chr(13) & cNum + 1 & ".", , , False)
- wRng.Collapse wdCollapseStart
- Set nRng = wRng.Paragraphs(1).Range
- If nRng Like "答案[::][A-D]" & Chr(13) Then
- aStr = aStr & cNum & Replace(Right(nRng, 2), Chr(13), "") & Chr(9)
- nRng.Delete
- Else
- aStr = aStr & cNum & "?" & Chr(9)
- End If
- cNum = cNum + 1
- Loop
- Set nRng = ActiveDocument.Paragraphs.Last.Range
- If nRng Like "答案[::][A-D]" & Chr(13) Then
- aStr = aStr & cNum & Replace(Right(nRng, 2), Chr(13), "")
- nRng.Select
- nRng.Delete
- Else
- aStr = aStr & cNum & "?"
- End If
- ActiveDocument.Content.InsertAfter Chr(13) & "【答案】" & Chr(13) & aStr
- End With
- End Sub
复制代码
|
|