|
Option Explicit
Sub test()
Dim ar, br, j&, r&, wdApp As Object, strFileName$, strPath$
Application.ScreenUpdating = False
ReDim ar(1 To 10 ^ 3, 1 To 9)
br = Array(2, 4, 6, 10, 12, 16, 18, 20)
On Error Resume Next
Set wdApp = GetObject(, "Word.Application")
If Err <> 0 Then
Set wdApp = CreateObject("Word.Application")
'wdApp.Visible = True
End If
strPath = ThisWorkbook.Path & "\"
strFileName = Dir(strPath & "*.doc")
Do Until strFileName = ""
With wdApp.documents.Open(strPath & strFileName)
With .Tables(1)
r = r + 1
For j = 0 To UBound(br)
ar(r, j + 1) = Left(.Range.Cells(br(j)).Range.Text, Len(.Range.Cells(br(j)).Range.Text) - 1)
Next j
End With
.Close False
End With
strFileName = Dir
Loop
Cells.Clear
If r Then [A1].Resize(r, UBound(ar, 2)) = ar
If Err <> 0 Then wdApp.Quit
Set wdApp = Nothing
Application.ScreenUpdating = True
Beep
End Sub
|
评分
-
2
查看全部评分
-
|