|
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
- Sub 读取文件()
- Dim oShell As Object
- Dim oFile As Object
- Dim oFldr As Object
- Dim lRow As Long
- Dim iCol As Integer
- Dim vArray As Variant
- vArray = Array(0, 10, 18, 176)
- Set oShell = CreateObject("Shell.Application")
- lRow = 1
- Set oFldr = oShell.Namespace(<span style="background-color: red;">*引用【Private Sub GetFiles】内的文件夹和子文件夹路径*</span>)
- With oFldr
- For iCol = LBound(vArray) To UBound(vArray)
- Cells(lRow, iCol + 1) = .getdetailsof(.Items, vArray(iCol))
- Next iCol
- For Each oFile In .Items
- lRow = lRow + 1
- For iCol = LBound(vArray) To UBound(vArray)
- On Error Resume Next
- Cells(lRow, iCol + 1) = .getdetailsof(oFile, vArray(iCol))
- Next iCol
- Next oFile
- End With
- End Sub
复制代码
Private Sub GetFiles(ByVal sPath$, ByVal sFileType$, ByRef Fso As Object, ByRef arr$(), ByRef m&)
Dim Folder As Object
Dim SubFolder As Object
Dim File As Object
Set Folder = Fso.GetFolder(sPath)
For Each File In Folder.Files
If File.Name Like sFileType Then
If File.Name <> ThisWorkbook.Name Then
m = m + 1
ReDim Preserve arr(1 To 2, 1 To m)
arr(1, m) = sPath & "\"
arr(2, m) = File.Name
End If
End If
Next
If Folder.SubFolders.Count > 0 Then
For Each SubFolder In Folder.SubFolders
Call GetFiles(SubFolder.Path, sFileType, Fso, arr, m)
Next
End If
Set Folder = Nothing
Set File = Nothing
Set SubFolder = Nothing
End Sub 需要是读取当前文件夹和子文件夹内的【jpg】格式图片属性(所有者,尺寸等),路径不是固定的需要是把excel放置到运行路径内
|
|