Sub 按钮1_Click()
With Application.FileDialog(msoFileDialogFolderPicker)
.InitialFileName = ThisWorkbook.Path & "\"
.Title = "请选择对应文件夹"
If .Show Then pth = .SelectedItems(1) Else Exit Sub '
End With
Set wdapp = CreateObject("word.application")
Set fso = CreateObject("scripting.filesystemobject")
wdapp.Visible = True
Set ff = fso.getfolder(pth).Files
ReDim arr(1 To ff.Count, 1 To 24)
brr = Array(3, 1, 2, 4, 1, 4, 5, 1, 6, 6, 2, 2, 7, 1, 4, 8, 2, 6, 9, 3, 2, 10, 3, 4, 11, 4, 2, 12, 4, 4, 13, 5, 2, 14, 6, 2, 15, 6, 4, 16, 7, 2, 17, 8, 2, 18, 9, 2, 19, 10, 2)
Application.ScreenUpdating = False
r = 0
For Each f In ff
With wdapp.documents.Open(f & "")
s = Format(WorksheetFunction.Clean(Split(.Paragraphs(2).Range.Text, ":")(1)), "yyyy-mm-dd")
r = r + 1
arr(r, 1) = r
arr(r, 2) = s
For j = 0 To UBound(brr) Step 3
arr(r, brr(j)) = "'" & WorksheetFunction.Clean(.tables(1).cell(brr(j + 1), brr(j + 2)).Range.Text)
Next j
crr = Split(Replace(WorksheetFunction.Clean(.tables(1).cell(11, 2).Range.Text), " ", ""), "盖章")
arr(r, 20) = crr(0)
arr(r, 21) = crr(UBound(crr))
crr = Split(Replace(WorksheetFunction.Clean(.tables(1).cell(12, 2).Range.Text), " ", ""), "盖章")
arr(r, 22) = Trim(crr(0))
arr(r, 23) = Trim(crr(UBound(crr)))
.Close False
End With
Next f
wdapp.Quit
rx = Cells(Rows.Count, 1).End(3).Row
Cells(rx, 1).Offset(2).Resize(r, UBound(arr, 2)) = arr
Application.ScreenUpdating = True
End Sub |