使用空超链接的工具提示

时间:2015-03-18 04:19:31

标签: excel excel-vba vba

我一直在寻找如何启用即兴工具提示。我遇到了一个教程,作者设法通过使用空的超链接来完成它。我能够在一个列上执行此操作,但我需要更大规模。我想出了一个for循环但由于某种原因我在if else语句中遇到了不匹配错误。这是:

Private Sub CommandButton2_Click()

    Dim IdentityRow As Long
    Dim SpecialIdentifier As String
    Dim ws1 As Worksheet

    Set ws1 = Sheets("Dashboard")

    For IdentityRow = 15 To 3000
    SpecialIdentifier = CStr(ws1.Range("B" & IdentityRow).Value)


    If SpecialIdentifier = "Rehire" Then

         ws1.Range("B" & IdentityRow).Hyperlinks.Add Anchor:=ws1.Range("B" & IdentityRow).Value, _
         Address:=" ", _
         ScreenTip:="User is a rehire, please remember to check HRI for current LM details", _
         TextToDisplay:=ws1.Range("B" & IdentityRow).Value


         ws1.Range("B" & IdentityRow).Font.Underline = xlUnderlineStyleNone
         ws1.Range("B" & IdentityRow).Font.Underline = black

      End If

   Next IdentityRow
End Sub

这是我遇到不匹配问题的地方:

ws1.Range("B" & IdentityRow).Hyperlinks.Add Anchor:=ws1.Range("B" & IdentityRow).Value, _
Address:=" ", _
ScreenTip:="User is a rehire, please remember to check HRI for current LM details", _
TextToDisplay:=ws1.Range("B" & IdentityRow).Value

任何想法?基本上我想将一行中的所有条目转换为空的超链接,只是为了获取工具提示。

谢谢你们。

1 个答案:

答案 0 :(得分:0)

您提供给Hyperlinks.Add的Anchor参数应该是Range,而不是Value。尝试:

Anchor:=ws1.Range("B" & IdentityRow)

而不是:

Anchor:=ws1.Range("B" & IdentityRow).Value

您还需要将ws1.Range("B" & IdentityRow).Font.Underline = black更正为ws1.Range("B" & IdentityRow).Font.Color = black以获取要运行的代码。

相关问题