超链接到工作簿中的特定 sheet

Hyperlinking to a specific sheet in the workbook

我正在尝试搜索名称为 TextBox1.Value 且已创建的 sheet。然后在名为 "Employee List" 的 sheet 和 hyperlink 上找到同名的 sheet 同名单元格。

它试图在我正在工作的文件夹中 link 到 "Name"。它甚至没有到达工作簿中。我是否缺少 .Hyperlinks 中的参数?

Dim findEmployee As Range
Dim foundEmployee As Range
Set findEmployee = Sheets("Employee List").Range("A:A")
Set foundEmployee = findEmployee.Find(TextBox1.Value)

With Worksheets("Employee List")
    .Hyperlinks.Add 
     Anchor:=.Range(foundEmployee.Address), _ Address:=Worksheets(TextBox1.Value).Range("A1"), _
     TextToDisplay:=TextBox1.Value
End With

你能试试这个吗?录制宏时,使用子地址而不是地址参数,而且必须是字符串形式而不是范围形式。如果您的 sheet 名称有空格,您需要在字符串中添加单引号。

Sub x()

Dim findEmployee As Range
Dim foundEmployee As Range

Set findEmployee = Sheets("Employee List").Range("A:A")
Set foundEmployee = findEmployee.Find(TextBox1.Value)

If Not foundEmployee Is Nothing Then
    With Worksheets("Employee List")
        .Hyperlinks.Add Anchor:=.Range(foundEmployee.Address), _
                        Address:="", _
                        SubAddress:=Worksheets(TextBox1.Value).Name & "!A1", _
                        TextToDisplay:=TextBox1.Value
    End With
End If

End Sub