|
[广告] VBA代码宝 - VBA编程加强工具 · VBA代码随查随用 · 内置多项VBA编程加强工具 ★ 免费下载 ★ ★ 使用手册★
代码更新一下,路径取值有改变。- Sub ykcbf() '//2024.7.26 加超链接
- Cells.Hyperlinks.Delete
- Application.ScreenUpdating = False
- Set fso = CreateObject("Scripting.FileSystemObject")
- p = ThisWorkbook.Path & ""
- On Error Resume Next
- With ThisWorkbook.Sheets("表1")
- r = .Cells(Rows.Count, 1).End(3).Row
- Set rng = .[e5].Resize(r - 4, 4)
- For i = 5 To r
- rq = .Cells(i, 2)
- nf = Left(rq, 4) & "年"
- yf = Val(Mid(rq, 5, 2)) & "月"
- p1 = p & nf & "" & yf & rq & ""
- For j = 5 To 8
- s = .Cells(i, j)
- For Each f In fso.GetFolder(p1).Files
- fn = fso.GetBaseName(f)
- If fn = s Then
- ss = f.Path
- ActiveSheet.Hyperlinks.Add Anchor:=.Cells(i, j), Address:=ss
- End If
- Next
- Next
- Next
- rng.Borders.LineStyle = 1
- End With
- Application.ScreenUpdating = True
- End Sub
复制代码
|
|