建立文件目录VBA

Sub folder()

Application.ScreenUpdating = False

Cells.Clear '清除当前表的内容

Dim folder As FileDialog '定义变量

Set folder = Application.FileDialog(msoFileDialogFolderPicker) '取浏览窗口之文件夹名称 With folder

.AllowMultiSelect = False '多选取消

If .Show = -1 Then folderpath = .SelectedItems(1) '当前所选文件夹

End With

Call ShowFolderList(folderpath) '调用ShowFolderList显示当前文件夹中的文件

Call subfolder(folderpath) '调用ShowFolderList显示当前文件夹子文件夹中的文件 '当前工作表中

Range("a1") = "所在文件夹/文件名:/大小/最后修改时间/类型" '为A本赋值

Columns("a:a").Select '选择A列

'以下为A列分列操作

Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _

TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _

Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _

:="/", FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1)), _

TrailingMinusNumbers:=True

'A到G列自动列宽

Dim i, n

i = Range("a65536").End(xlUp).Row

For n = 2 To i

Range("b" & n).Select

ActiveSheet.Hyperlinks.add Anchor:=Selection, Address:=Cells(n, 1) & "\" & Cells(n, 2) Next

Columns("a:g").AutoFit

Application.ScreenUpdating = True

End Sub

Sub subfolder(folderpath)

If folderpath "" Then

Set fs = CreateObject("scripting.filesystemobject") '创建调用脚本

Set f = fs.GetFolder(folderpath) '调用文件夹中的子文件夹

Set fss = f.SubFolders

For Each subf In fss

subfolder (subf) '递归调用

ShowFolderList (subf) '调用子程序显示子文件夹中文件

Next

Else

Exit Sub

End If

End Sub

Sub ShowFolderList(folderspec)

On Error Resume Next

Dim fs, f, f1, fc, s

Set fs = CreateObject("Scripting.FileSystemObject")

Set f = fs.GetFolder(folderspec)

Set fc = f.Files

If fc.Count 0 Then

Set d = CreateObject("scripting.dictionary")

For Each f1 In fc

d.add f1.ParentFolder & "/" & f1.Name & "/" & Int(f1.Size / 1024) & "KB" & "/" & f1.DateCreated & "/" & f1.Type, ""

Next

Range("a" & [a65536].End(xlUp).Row

WorksheetFunction.Transpose(d.keys)

Else

Exit Sub

End If

Set d = Nothing

Set e = Nothing

Set f = Nothing

End Sub + 1).Resize(fc.Count, 1) =

Sub folder()

Application.ScreenUpdating = False

Cells.Clear '清除当前表的内容

Dim folder As FileDialog '定义变量

Set folder = Application.FileDialog(msoFileDialogFolderPicker) '取浏览窗口之文件夹名称 With folder

.AllowMultiSelect = False '多选取消

If .Show = -1 Then folderpath = .SelectedItems(1) '当前所选文件夹

End With

Call ShowFolderList(folderpath) '调用ShowFolderList显示当前文件夹中的文件

Call subfolder(folderpath) '调用ShowFolderList显示当前文件夹子文件夹中的文件 '当前工作表中

Range("a1") = "所在文件夹/文件名:/大小/最后修改时间/类型" '为A本赋值

Columns("a:a").Select '选择A列

'以下为A列分列操作

Selection.TextToColumns Destination:=Range("A1"), DataType:=xlDelimited, _

TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, _

Semicolon:=False, Comma:=False, Space:=False, Other:=True, OtherChar _

:="/", FieldInfo:=Array(Array(1, 1), Array(2, 1), Array(3, 1)), _

TrailingMinusNumbers:=True

'A到G列自动列宽

Dim i, n

i = Range("a65536").End(xlUp).Row

For n = 2 To i

Range("b" & n).Select

ActiveSheet.Hyperlinks.add Anchor:=Selection, Address:=Cells(n, 1) & "\" & Cells(n, 2) Next

Columns("a:g").AutoFit

Application.ScreenUpdating = True

End Sub

Sub subfolder(folderpath)

If folderpath "" Then

Set fs = CreateObject("scripting.filesystemobject") '创建调用脚本

Set f = fs.GetFolder(folderpath) '调用文件夹中的子文件夹

Set fss = f.SubFolders

For Each subf In fss

subfolder (subf) '递归调用

ShowFolderList (subf) '调用子程序显示子文件夹中文件

Next

Else

Exit Sub

End If

End Sub

Sub ShowFolderList(folderspec)

On Error Resume Next

Dim fs, f, f1, fc, s

Set fs = CreateObject("Scripting.FileSystemObject")

Set f = fs.GetFolder(folderspec)

Set fc = f.Files

If fc.Count 0 Then

Set d = CreateObject("scripting.dictionary")

For Each f1 In fc

d.add f1.ParentFolder & "/" & f1.Name & "/" & Int(f1.Size / 1024) & "KB" & "/" & f1.DateCreated & "/" & f1.Type, ""

Next

Range("a" & [a65536].End(xlUp).Row

WorksheetFunction.Transpose(d.keys)

Else

Exit Sub

End If

Set d = Nothing

Set e = Nothing

Set f = Nothing

End Sub + 1).Resize(fc.Count, 1) =


相关文章

  • Access编程入门
  • 支持 / Access / 访问 2007年帮助和操作方法 / 宏与可编程性 是 Access 编程新手吗?请从这里开始 适用于: Microsoft Office Access 2007 在创建新数据库时,您通常首先创建几个数据库对象(如 ...查看


  • 语言文字信息处理整理
  • 一. 1. 2. 3. 4. 5. 6. 7. 8. 9. 10.填空选择目前计算机系统的工作原理是由冯·诺依曼提出来的.在微型计算机存储器中,不能修改其存储内容的是ROM .HTTP 是一种超文本传输协议.Symbian 操作系统属于嵌入 ...查看


  • Workbooks对象的Open方法的帮助说明(VBA)
  • http://www.excelpx.com/home/show.aspx?id=11569&cid=15 [日期:2008-11-23] 来源:  作者: [字体:大 中 小] 下面的这些内容,在Excel的VBA帮助中可以找到, ...查看


  • 问卷调查系统的设计与实现----谢传海
  • 郑州师范学院 毕业论文(设计) 题目 问卷调查系统的设计与实现 姓名 学号 院 系信息科学与技术学院 专业计算机可与与技术 年级班级 2016年5月20日 毕业论文(设计)作者声明 本人郑重声明:所呈交的毕业论文是本人在导师的指导下独立进行 ...查看


  • 办公软件高级应用考试大纲
  • 办公软件高级应用技术(二级)考试大纲 2008-09-01 基本要求 1掌握Office各组件的运行环境和视窗元素. 2.掌握Word高级应用技术,能够熟练掌握页面.样式.域的设置和文档修订. 3.掌握Excel高级应用技术,能够熟练掌握工 ...查看


  • 办公室自动化
  • 办公自动化问答 位置:主页>>办公自动化>>办公自动化问答 1,Q:为什么要用 Windows 下的文字处理软件 WPS97/2000.iWPS.net.Office WPS.Office97/2000/XP 等? ...查看


  • VBA编程实现工商银行批量转账工具软件
  • VBA编程实现工商银行批量转账工具软件 摘要:工商银行为个人客户提供批量转账服务,个人客户可以通过工行网上银行进行批量转账,免手续费.该文介绍了通过vba编程制作工商银行批量转账工具软件的原理,使其能够导入并处理excle文件,自动生成用于 ...查看


  • vba编程常用英文单词100个
  • 大家好,部分朋友在公众号留言,建议把vba常用英文单词发一下,我把我常用的记录下来,也行还有一些没有记到,大家可以在公众号文章留言处补充. 1.   Sub 开始 2.   End结束 3.   iif如果函数 4.   path路径 5. ...查看


  • 小型超市收银系统的设计与实现
  • 学号 题目: 作 者 届 别 院 别 专 业 指导教师职 称 完成时间 摘 要 随着销售行业竞争日益激烈,小型超市收银系统的引入显得极其重要.它不但可以提高进销存管理的工作效率,而且可以有效减少盲目采购.降低采购成本.合理控制库存.减少资金 ...查看


热门内容