想要从文件夹中提取文件名,并使用相同的文件创建超链接



我想从文件夹中获取所有文件名,并用相同的文件创建超链接。

下面提到的是我的代码,请协助。

Sub FileName1()
Dim I As Integer
Dim fl As File
Dim fldr As Folder
Dim SH As Worksheet
Dim fso As FileSystemObject
Dim Fpath As String
Dim mpath As String
With Application.FileDialog(msoFileDialogFolderPicker)
.Show
Fpath = .SelectedItems(1)
mpath = Fpath & ""
End With
I = 1
Set fso = New FileSystemObject
Set fldr = fso.GetFolder(Fpath)
For Each fl In fldr.Files
First.Cells(I, 1) = fl.Name
If First.Cells(I, 1) = fl.Name Then
First.Cells(I, 1).Select
First.Hyperlinks.Add Anchor:=First.Cells(I, 1), Address:=mpath,  TextToDisplay:=First.Cells(I, 1)
End If
I = I + 1
Next fl
End Sub

更改

First.Hyperlinks.Add Anchor:=First.Cells(I, 1), Address:=mpath,  TextToDisplay:=First.Cells(I, 1)

First.Hyperlinks.Add Anchor:=First.Cells(I, 1), Address:=mpath & fl.Name,  TextToDisplay:=First.Cells(I, 1).Value

最新更新