|
楼主 |
发表于 2022-12-3 20:53
|
显示全部楼层
谢谢老师回复!
比如如下:
- Sub TEST()
- Dim strFileName$, strPath$, wkb As Workbook, dic As Object, vKey
- Application.ScreenUpdating = False
- Set dic = CreateObject("Scripting.Dictionary")
- strPath = ThisWorkbook.Path & ""
- strFileName = Dir(strPath & "*.xls*")
- Do Until strFileName = ""
- If strFileName <> ThisWorkbook.Name Then
- Set wkb = GetObject(strPath & strFileName)
- arr = wkb.Sheets(1).[A1].CurrentRegion
- dic(FName(strFileName)) = arr
- wkb.Close False
- End If
- strFileName = Dir
- Loop
- For Each vKey In dic.keys
- 'dic (vKey) '就是数组,根据需要进行处理
- Next
- Set wkb = Nothing
- Set dic = Nothing
-
- Sheet2.Cells(1, 1).Resize(UBound(dic(花花)), UBound(dic(花花), 2)) = dic(花花)
- Sheet2.Cells(1, 9).Resize(UBound(dic(三国)), UBound(dic(三国), 2)) = dic(三国)
- Application.ScreenUpdating = True
- End Sub
- Function FName(FileName As Variant) As String
- Application.Volatile
- FName = Left(FileName, InStrRev(FileName, ".") - 1)
- End Function
复制代码 后续,怎么用啊?
|
|