[英]excel vba insert hyperlink with cell reference into cell when cell is clicked?
我想創建代碼,當單擊該單元格時,它將在該單元格中插入一個超鏈接。
我正在使用以下代碼:
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。
這樣做時,我收到“對象未定義錯誤”消息。 是什么導致該錯誤?
引號太多。
請試試這個:
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
此項目引起的代碼錯誤:
& Range(""B"" & Active.Row).Value
內超鏈接公式。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.