|
本帖最后由 huanger999 于 2014-10-21 21:56 编辑
- Sub new_doc()
- Dim mydoc As Document '现有文档
- Dim newdoc As Document '新建文档
- strinput = InputBox("请输入题号,以半角逗号分隔!")
- If strinput = False Then
- 'MsgBox "没有输入"
- Exit Sub
- End If
- '建立一个列表,index对应题号,值对应段落号
- strlist = "id"
- myMax = 0
- For i = 1 To ActiveDocument.Paragraphs.Count
- If ActiveDocument.Paragraphs(i).Range.ListFormat.ListString <> "" Then
- strlist = strlist & "," & i
- myMax = CInt(Replace(ActiveDocument.Paragraphs(i).Range.ListFormat.ListString, ".", ""))
- End If
- Next i
- strlist = strlist & "," & ActiveDocument.Paragraphs.Count
- strArray = Split(strlist, ",")
- orderlist = strinput
- orderArray = Split(orderlist, ",")
- Set mydoc = ActiveDocument
- Set newdoc = Documents.Add
- strStatus = "ID copyed"
- For i = 0 To UBound(orderArray)
- questionID = CInt(orderArray(i))
- If questionID <= myMax Then
- mydoc.Activate
- mystart = mydoc.Paragraphs(CInt(strArray(questionID))).Range.Start
- myend = mydoc.Paragraphs(CInt(strArray(questionID + 1))).Range.Start
- mydoc.Range(mystart, myend).Copy
- newdoc.Activate
- Selection.PasteAndFormat (wdPasteDefault)
- strStatus = strStatus & ", " & orderArray(i)
- End If
- Next i
- MsgBox strStatus
- End Sub
复制代码 |
|