【问题标题】:Hyperlinking to a specific sheet in the workbook超链接到工作簿中的特定工作表
【发布时间】:2019-01-16 19:22:05
【问题描述】:

我正在尝试搜索已创建的名称为 TextBox1.Value 的工作表。然后在名为“员工列表”的工作表上找到同名,并将该单元格超链接到同名工作表。

它试图链接到我正在工作的文件夹中的“名称”。它甚至没有到达工作簿内部。我在.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

【问题讨论】:

    标签: excel vba hyperlink range worksheet


    【解决方案1】:

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

    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
    

    【讨论】:

    • 他们都有空格。我会将这些单引号放在哪个字符串周围,工作表名称?
    • "'" & Worksheets(TextBox1.Value).Name & "'!A1"
    猜你喜欢
    • 2011-06-16
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-03-28
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多