|
* 请 楼主 自行删除不必要的空白段落,然后,如果不满意排序的结果,可以重新调入文档,再执行一次。
- Sub test_查找下划线单词_随机排序()
- Dim n&, s$, x$, i&, r&, t$, arr, a As Range
- With ActiveDocument.Content.Find
- .ClearFormatting
- .Text = ""
- .Font.Underline = wdUnderlineSingle
- .Forward = True
- .MatchWildcards = True
- Do While .Execute
- n = n + 1
- With .Parent
- s = s & " " & n & "." & .Text
- x = x & "/" & .Text
- If n = 1 Then .Select: Set a = Selection.Paragraphs(1).Range
- End With
- Loop
- End With
- ActiveDocument.Content.InsertAfter Text:=vbCr & "参考答案:" & s
- ActiveDocument.Paragraphs.Last.Range.Select
- Selection.Range.ListFormat.RemoveNumbers NumberType:=wdNumberParagraph
- Selection.TypeParagraph
- ActiveDocument.Paragraphs.Last.Range.Characters(6).Text = vbCr
- x = Right(x, Len(x) - 1)
- arr = Split(x, "/")
- Randomize
- For i = 0 To n - 1
- r = Int(Rnd * (n - i + 1)) + i
- If r = 5 Then Exit For
- t = arr(r)
- arr(r) = arr(i)
- arr(i) = t
- Next
- a.InsertBefore Text:=Join(arr, " ") & vbCr
- a.Paragraphs(1).Range.ListFormat.RemoveNumbers NumberType:=wdNumberParagraph
- Selection.HomeKey 6
- End Sub
复制代码 |
评分
-
1
查看全部评分
-
|