VBA超链接.添加到同一工作表中的另一个单元格



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

循环调用以下代码,其中"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,Object不支持此属性或方法",我尝试了硬编码而不是使用命名的范围/变量,并花时间查看其他超链接。在更改错误行的格式时添加示例,但我无法运行代码。

非常感谢您的帮助!

我开始工作了(将temp调为字符串,在超链接公式中,anchor:=takawaypasterange和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

相关内容

最新更新