Sub
FSO_FileExtraction()
Dim
strFldPath
As
String
With
Application.FileDialog(msoFileDialogFolderPicker)
.Title =
"请选择指定文件夹。"
If
.Show
Then
strFldPath = .SelectedItems(1)
Else
Exit
Sub
End
If
End
With
Application.ScreenUpdating =
False
Range(
"a:b"
).ClearContents
Range(
"a1:b1"
) = Array(
"文件夹"
,
"文件名及超链接"
)
Call
ExtractionFileAddHyperlinks(strFldPath)
Range(
"a:b"
).EntireColumn.AutoFit
Sheets(
"Sheet1"
).
Select
Sheets(
"Sheet1"
).Copy
ActiveSheet.Shapes.Range(Array(
"Button 1"
)).Delete
ActiveWorkbook.SaveAs Filename:= _
strFldPath &
"\文档目录.xlsx"
, FileFormat:= _
xlOpenXMLWorkbook, CreateBackup:=
False
ActiveWorkbook.Close
Application.ScreenUpdating =
True
Range(
"a:c"
).ClearContents
Columns(
"A:C"
).ColumnWidth = 8.08
ThisWorkbook.Save
End
Sub
----------------------------------------
Sub
文件提取()
Function
ExtractionFileAddHyperlinks(
ByVal
strFldPath
As
String
)
As
String
Dim
objMyFSO
As
Object
Dim
objFld
As
Object
Dim
objFile
As
Object
Dim
objSubFld
As
Object
Dim
strFilePath
As
String
Dim
lngLastRow
As
Long
Dim
intNum
As
Integer
Set
objMyFSO = CreateObject(
"Scripting.FileSystemObject"
)
Set
objFld = objMyFSO.GetFolder(strFldPath)
For
Each
objFile
In
objFld.Files
lngLastRow = Cells(Rows.Count, 1).
End
(xlUp).Row + 1
strFilePath = objFile.Path
intNum = InStrRev(strFilePath, "\")
Cells(lngLastRow, 2) = Left(strFilePath, intNum - 1)
Cells(lngLastRow, 1) = Mid(strFilePath, intNum + 1)
Next
objFile
For
Each
objSubFld
In
objFld.SubFolders
Call
ExtractionFileAddHyperlinks(objSubFld.Path)
Next
objSubFld
Set
objMyFSO =
Nothing
Set
objFld =
Nothing
Set
objFile =
Nothing
Set
objSubFld =
Nothing
End
Function