简体   繁体   English

Excel VBA单击单元格时,将带有单元格引用的超链接插入单元格?

[英]excel vba insert hyperlink with cell reference into cell when cell is clicked?

I want to create code, which will insert an hyperlink into a cell when that cell is clicked. 我想创建代码,当单击该单元格时,它将在该单元格中插入一个超链接。

I'm using the following code: 我正在使用以下代码:

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

What I want is to be able to build part of my hyperlink path with text, then get the rest of the hyperlink url using Range("B" & Active.Row), which will get the value from the cell on the active row and complete the hyperlink url. 我想要的是能够用文本构建我的超链接路径的一部分,然后使用Range(“ B”&Active.Row)获取其余的超链接URL,这将从活动行上的单元格中获取值,并完成超链接URL。

I get an "Object Undefined Error" message when I do this. 这样做时,我收到“对象未定义错误”消息。 What's causing that error? 是什么导致该错误?

there is too many quote symbols. 引号太多。

Please try this one: 请试试这个:

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

Your code error caused by this item: 此项目引起的代码错误:

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

inside hyperlink formula. 内超链接公式。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM