|
本帖最后由 爱疯 于 2019-3-29 20:40 编辑
Option Explicit
'入口
Sub wd2sht()
Dim p, f, s, A(1 To 10 ^ 4, 1 To 7) '指定列的范围
'1)清除
Application.ScreenUpdating = False
Sheets(1).Select
[a:g] = ""
Range("e:e").NumberFormat = "@"
'2)收集到数组
p = ThisWorkbook.Path & "\"
f = Dir(p & "*.doc")
Do While f <> ""
Call wd2arr(A, f, s, GetObject(p & f))
f = Dir()
Loop
'3)输出
[a1:g1] = Array("姓名", "性别", "出生年月", "与户主关系", "身份证号", "备注", "文件名")
[a2].Resize(UBound(A), UBound(A, 2)) = A
With [a:g]
.Replace Chr(7), ""
.Replace Chr(13), ""
End With
End Sub
'Wd到数组
Sub wd2arr(A, f, s, wd)
Dim n, i, j
For n = 1 To wd.tables.Count
With wd.tables(n)
''''''''''''''''''''''''''''''''''''''''''''''''''
'1)户主
s = s + 1
A(s, 1) = .cell(1, 2)
A(s, 2) = .cell(2, 2)
A(s, 3) = .cell(2, 4)
A(s, 4) = "户主"
A(s, 5) = .cell(1, 4)
A(s, 7) = f
''''''''''''''''''''''''''''''''''''''''''''''''''
'2)成员
For i = 6 To 12 '行的范围
If .cell(i, 1) <> Chr(13) & Chr(7) Then
s = s + 1
For j = 1 To 6 '列的范围
A(s, j) = .cell(i, j) '.Range.Text
Next j
A(s, j) = f
End If
Next i
''''''''''''''''''''''''''''''''''''''''''''''''''
End With
Next n
End Sub
4.rar
(31.72 KB, 下载次数: 118)
|
|