【问题标题】:VBA Hyperlink.Add to another cell in the same WorksheetVBA 超链接。添加到同一工作表中的另一个单元格
【发布时间】:2020-03-04 01:44:21
【问题描述】:

我想为工作表上输入的每个外卖创建一个超链接,并将所有超链接放置在输入外卖的下方的动态范围内。

循环调用以下代码,其中“pkey”是包含宏检测到的触发器的工作表的名称(创建 1 到 1 的超链接):

Public Sub Takeaways(ByVal ws As Worksheet, ByVal table As Range, ByVal pkey As String)

Dim Lastcolumn As Long
Dim takeawaylastrow As Long
Dim takeawayfirstrow As Range
Dim takeawaypasterange As Range
Dim takeaway_description As String

Lastcolumn = ws.Cells(table.row, Columns.count).End(xlToLeft).column
takeaway_description = ws.Cells(table.row, Lastcolumn)
Set takeawayfirstrow = ws.Range("Takeaways").Offset(0, 1)
takeawaylastrow = ws.Range("Takeaways").Offset(0, 1).End(xlDown).row
Set takeawaypasterange = ws.Cells(takeawaylastrow + 1, New_Meeting_Task_Columns.Trigger)

takeawaypasterange = takeaway_description

ThisWorkbook.Worksheets(pkey).Hyperlinks.Add Anchor:=ThisWorkbook.Worksheets(pkey) & "!" & Cells.takeawaypasterange.Address, Address:="", SubAddress:=ThisWorkbook.Worksheets(pkey).table(1, 1).Address, TextToDisplay:="Takeaway"

End sub

最后一行代码产生错误“438,对象不支持此属性或方法”,我尝试硬编码而不是使用命名范围/变量,并花时间查看其他超链接。添加示例更改错误行的格式时,但无法运行代码。

非常感谢您的帮助!

【问题讨论】:

  • 尝试只用takeawaypasterange.Address替换Cells.takeawaypasterange.Address...

标签: excel vba hyperlink


【解决方案1】:

我让它工作了(dim temp 作为字符串,在超链接公式中,anchor:= takeawaypasterange 和 subaddress:=temp 成功了)

Public Sub Takeaways(ByVal ws As Worksheet, ByVal table As Range, ByVal pkey As String)

Dim Lastcolumn As Long
Dim takeawaylastrow As Long
Dim takeawayfirstrow As Range
Dim takeawaypasterange As Range
Dim takeaway_description As String

dim temp as string

Lastcolumn = ws.Cells(table.row, Columns.count).End(xlToLeft).column
takeaway_description = ws.Cells(table.row, Lastcolumn)
Set takeawayfirstrow = ws.Range("Takeaways").Offset(0, 1)
takeawaylastrow = ws.Range("Takeaways").Offset(0, 1).End(xlDown).row
Set takeawaypasterange = ws.Cells(takeawaylastrow + 1, New_Meeting_Task_Columns.Trigger)

takeawaypasterange = takeaway_description
temp = table(1, 1).Address

ThisWorkbook.Worksheets(pkey).Hyperlinks.Add Anchor:=takeawaypasterange, _
Address:="", SubAddress:=temp, TextToDisplay:="testttttt"

End sub

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-03-28
    • 2015-09-22
    • 1970-01-01
    • 1970-01-01
    • 2017-09-29
    相关资源
    最近更新 更多