【问题标题】:Hyperlink.add Anchor with .Cells instead of .RangeHyperlink.add Anchor with .Cells 而不是 .Range
【发布时间】:2016-11-10 18:24:22
【问题描述】:

我有一些代码似乎无法正常工作,如下所示

With Cells(emptyRow, 13)
     .Hyperlinks.Add Anchor:=.Cells(emptyRow, 13), _
     Address:=EmailLinkTextBox.Value, TextToDisplay:="Link"
End With

我相信这是由于锚点,因为我发现锚点的描述表明它可以是 Range 或 Shape 对象。

这是问题吗,如果是的话,有什么办法让它工作吗?

谢谢

【问题讨论】:

  • 感谢您的评论,它为我指明了正确的方向并解决了我的问题。代码现在很简单.Hyperlinks.Add Anchor:=.Cells(emptyRow, 13), Address:=EmailLinkTextBox.Value, TextToDisplay:="Link"
  • 我想我可能不小心删除了原来的评论,对不起!

标签: excel macros vba


【解决方案1】:

当您将锚点设置为With Cells(emptyRow, 13) 块内的地址.Cells(emptyRow, 13)(即等同于Cells(emptyRow, 13).Cells(emptyRow, 13),锚点将被放置在Cells(2 * emptyRow - 1, 2 * 13 - 1)

您可能希望将锚点更改为 Cells(emptyRow, 13) - 即将您的代码替换为:

With Cells(emptyRow, 13)
     .Hyperlinks.Add Anchor:=Cells(emptyRow, 13), _
     Address:=EmailLinkTextBox.Value, TextToDisplay:="Link"
End With

With Cells(emptyRow, 13)
     .Hyperlinks.Add Anchor:=.Cells(1, 1), _
     Address:=EmailLinkTextBox.Value, TextToDisplay:="Link"
End With

注意:CellRange 对象 - 只是它只有 1 x 1 大小。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2023-01-21
    • 2020-03-28
    • 2021-11-29
    • 2019-01-09
    相关资源
    最近更新 更多