【问题标题】:excel vba insert hyperlink with cell reference into cell when cell is clicked?单击单元格时,excel vba将带有单元格引用的超链接插入单元格?
【发布时间】:2014-11-20 03:06:27
【问题描述】:

我想创建代码,当单击该单元格时,该代码将在该单元格中插入一个超链接。

我正在使用以下代码:

If Target.Column = Range("BL1").Column Then
    If Target.Row > 14 And Target.Value = "Attach" Then

    MsgBox "This is fun"
    Range("BL" & Target.Row).Formula = "=HYPERLINK(""\\UKSH000-file06\purchasing\New_Supplier_Set_Ups_&_Audits\ATTACHMENTS\"" & Range(""B"" & Active.Row).Value & "",""Attached"")"

    End If
End If

我想要的是能够用文本构建我的超链接路径的一部分,然后使用 Range("B" & Active.Row) 获取超链接 url 的其余部分,这将从上的单元格中获取值活动行并完成超链接 url。

我在执行此操作时收到“对象未定义错误”消息。是什么导致了这个错误?

【问题讨论】:

  • 在哪一行得到对象未定义错误?

标签: vba excel


【解决方案1】:

引号太多了。

请试试这个:

Dim ws As Worksheet
ws = Target.Parent

    If Target.Column = Range("BL1").Column Then
        If Target.Row > 14 And Target.Value = "Attach" Then

        MsgBox "This is fun"
        ws.Hyperlinks.Add _
          Anchor:=Range("BL" & Target.Row), _
          Address:="\\UKSH000-file06\purchasing\New_Supplier_Set_Ups_&_Audits\ATTACHMENTS\" & _
                   Range("B" & Active.Row).Value, _
          TextToDisplay:="Attached"

        End If
    End If

【讨论】:

    【解决方案2】:

    您的代码错误是由这个项目引起的:

    & Range(""B"" & Active.Row).Value
    

    在超链接公式内。

    【讨论】:

      猜你喜欢
      • 2016-08-23
      • 2017-05-30
      • 1970-01-01
      • 1970-01-01
      • 2016-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多