|
代码放Excel中:
- Sub test()
- Dim i%, j%, k%, f$, FileName$, wd, arr(1 To 10000, 1 To 4)
- Set wd = CreateObject("Word.Application")
- f = ThisWorkbook.Path
- FileName = Dir(f & "\*.doc*")
- k = 0
- Do While FileName <> ""
- With wd.Documents.Open(f & "" & FileName)
- k = k + 1
- arr(k, 1) = Left(FileName, InStrRev(FileName, ".") - 1)
- arr(k, 2) = Replace(.Paragraphs(1).Range.Text, Chr(13), "")
- arr(k, 3) = Replace(.Paragraphs(2).Range.Text, Chr(13), "")
- arr(k, 4) = "考生得分" & Split(Replace(.Paragraphs(3).Range.Text, Chr(13), ""), "考生得分")(1)
- .Close False
- End With
-
- FileName = Dir
- Loop
- wd.Quit
- Set wd = Nothing
- If k = 0 Then MsgBox "没有数据!": Exit Sub
- With Sheets("Sheet1")
- .Range("A2:D" & .Cells(.Rows.Count, 1).End(xlUp).Row + 1).ClearContents
- .[A2].Resize(k, 4) = arr
- End With
- MsgBox "汇总完成!"
- End Sub
复制代码
|
|