文件夹内形式
可以看到文件夹内文件的格式都不同。
VBA代码
Sub addHyper()
Set fso = CreateObject("Scripting.FileSystemObject")
folder_location = "E:\CPA会计-张敬富\讲义\"
Set Files = fso.GetFolder(folder_location).Files
i = 0
For Each file In Files
i = i + 1
fn = file.Name
Selection.Offset(1, 0).Select
Selection = Str(i) & ". " & fso.GetBaseName(fn)
ActiveSheet.Hyperlinks.Add anchor:=Selection, Address:=folder_location & fn
Next
End Sub
运行结果
选中某一单元格,输出结果会在此单元格后方出现
运行代码
自动读取文件夹中文件名并为其添加上超链接。