|
楼主 |
发表于 2016-1-5 21:14
|
显示全部楼层
[广告] Excel易用宝 - 提升Excel的操作效率 · Excel / WPS表格插件 ★ 免费下载 ★ ★ 使用帮助★
谢谢您!按您的方法我修改测试了,有错误,无法获取文件夹内所有文件名称了。
原全部代码如下:
Sub Fileinfo()
Sheets(1).Range("A1").Select
Dim fd As FileDialog
Set fd = Application.FileDialog(msoFileDialogFolderPicker)
If fd.Show = -1 Then GetDirectory = fd.SelectedItems(1)
Dim c As Long, R As Long, i As Long
Dim FileName As Object, ObjShell As Object, ObiFolder As Object
Set ObjShell = CreateObject("shell.Application")
Set ObiFolder = ObjShell.Namespace(GetDirectory)
On Error Resume Next
c = 0
For i = 0 To 34
If i = 27 Or i = 28 Or i = 29 Or i = 31 Then
'
Else
c = c + 1
Cells(1, c) = ObiFolder.getdetailsof(ObiFolder.Items, i)
End If
Next i
R = 1
For Each FileName In ObiFolder.Items
c = 0
R = R + 1
For i = 0 To 34
If i = 27 Or i = 28 Or i = 29 Or i = 31 Then
'
Else
c = c + 1
Cells(R, c) = ObiFolder.getdetailsof(FileName, i)
End If
Next i
Next FileName
ActiveSheet.ListObjects.Add xlSrcRange, [A1].CurrentRegion
Set fd = Nothing
End Sub
我把第3-5句按您的建议改成了:
Dim ipath$
ipath = ThisWorkbook.path '当前代码工作簿所在路径赋值给变量ipath
If ipath = -1 Then GetDirectory = ipath.SelectedItems(1)
就无法获取文件名了
还请您再指点,谢谢! |
|