|
各位大神,本人VBA小白,想实现以下功能:根据单元格内的文件名,查找指定路径里的文件夹,如果有该文件名则自动加上超链接,在论坛里找到了版主:liulang0808 写的一段代码比较适合,但该代码是给固定某一列加入超链接,我是想给某一个区域所有单元格都加上。无奈本人不会修改,请大神帮帮忙,帮我完善一下,附件里有文件。谢谢!
Dim sh As Worksheet
Dim rng As Range
Sub 按钮1_Click()
Application.ScreenUpdating = False
For Each sh In Sheets
With sh
For j = 2 To .Cells(Rows.Count, 2).End(3).Row
If Len(.Cells(j, 2)) > 0 Then
Set rng = .Cells(j, 2)
Getfd (ThisWorkbook.Path)
End If
Next j
End With
Next sh
Application.ScreenUpdating = True
End Sub
Sub Getfd(ByVal pth)
Set Fso = CreateObject("scripting.filesystemobject")
Set ff = Fso.getfolder(pth)
For Each f In ff.Files
If InStr(f.Name, rng.Value) > 0 Then
sh.Hyperlinks.Add Anchor:=rng, Address:=f
Exit Sub
End If
Next f
For Each fd In ff.subfolders
Getfd (fd)
Next fd
End Sub
'此代码来源于EXCELHOME论坛版主:liulang0808,感谢版主分享,本人初识VBA,纯小白,肯请各位大神帮忙完善一下,万分感谢!
|
|