|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
'名称要跟表格中的完全一样,就像"血糖"表格中叫"葡萄糖(GLU)",,,
Option Explicit
Sub test()
Dim arr, i, j, dic, filename(), t, brr
Set dic = CreateObject("scripting.dictionary")
arr = [a1].CurrentRegion
For i = 5 To UBound(arr, 2): dic(arr(1, i)) = i: Next
ReDim arr(1 To Rows.Count, 1 To UBound(arr, 2))
If Not getfilename(ThisWorkbook.Path, filename, ".xls") Then MsgBox "!": Exit Sub
For i = 1 To UBound(filename)
t = Split(filename(i), "\"): arr(i, 1) = Split(t(UBound(t)), ".")(0)
With GetObject(filename(i))
With .ActiveSheet
brr = .Range("a2:e" & .Cells(.Rows.Count, "a").End(xlUp).Row)
arr(i, 2) = Split(Split(brr(1, 1), "姓名:")(1))(0)
arr(i, 3) = Split(Split(brr(1, 1), "性别:")(1))(0)
arr(i, 4) = Split(brr(1, 1), "年龄:")(1)
For j = 2 To UBound(brr, 1)
If dic.exists(brr(j, 1)) Then arr(i, dic(brr(j, 1))) = brr(j, 2)
Next
End With
.Close
End With
Next
With [a2]
.Resize(Rows.Count - 1, UBound(arr, 2)).ClearContents
.Resize(i - 1, UBound(arr, 2)) = arr
End With
End Sub
Function getfilename(pth, filename, mark) As Boolean
Dim f, n
pth = pth & IIf(Right(pth, 1) = "\", "", "\")
f = Dir(pth & "*.*")
Do Until Len(f) = 0
If LCase(Right(f, Len(mark))) = LCase(mark) Then
n = n + 1: ReDim Preserve filename(1 To n)
filename(n) = pth & f
End If
f = Dir
Loop
If n > 0 Then getfilename = True
End Function |
评分
-
1
查看全部评分
-
|