链接本文件的单元格:
ActiveSheet.Hyperlinks.Add Range("A1"), "", "单元格地址", Range("A1").Text
链接外部文件或网页等:
ActiveSheet.Hyperlinks.Add Range("A1"), "超链接地址", , Range("A1").Text
Sub setLinks()Dim r As Range
Dim a As Range
Dim s As String
Set a = Range("A1:A5")
For Each r In a
r.Select
s = r.Value
If s <>"" Then
ActiveSheet.Hyperlinks.Add Anchor:=Selection, Address:="", SubAddress:= _
s &"!A1", TextToDisplay:=s
End If
Next r
End Sub
只要把上面方法里的Set a = Range("A1:A5")里的范围改成你“目录”中的A6-A13,A133-A139……这些内容所在单元格的范围就行了。
代码示例如下:
Private Sub CommandButton21_Click()With Sheet1
.Hyperlinks.Add .Range("A3"), "
End With
End Sub
效果如图:
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)