如果以后我从其中任何一个删除了任何超链接,为什么Excel删除所有粘贴的超链接?
我正在使用以下代码将超链接从一个单元格复制到一个范围。
超链接已被粘贴并尽其所能,
但是,如果我以后从任何一个粘贴的超链接中删除了任何超链接,则删除了目的地单元格的所有超链接!
这个问题发生在我使用VBA(复制,粘贴& delete)或仅使用Excel。
我正在使用Office 2016。
Sub Hyperlinks_Issue()
Range("R2").Copy Range("N2:N15")
Range("N2").Hyperlinks.Delete
End Sub
I am using the below code to copy hyperlink from one cell to a range.
The hyperlinks have been pasted and working as it should,
But if I later removed any hyperlink from any one of pasted hyperlinks ,then all hyperlinks from destination cells are deleted !!
This issue happens either I have used vba (copy, paste & delete) or used merely excel.
I am using office 2016.
Sub Hyperlinks_Issue()
Range("R2").Copy Range("N2:N15")
Range("N2").Hyperlinks.Delete
End Sub
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题与以下事实有关。代码> N2:N15 。您可以通过立即插入以下代码来检查此问题:
debug.print(range(“ n2:n15”)。hyperlinks.count)
此返回
1
,意味着整个范围只有一个超链接(如您所期望的,而不是14个)。如果然后检查此信息:debug.print(range(“ n2”)。超链接(1).range.Address)
您会看到它返回
$ n $ 2:$ n $ N $ 15 < /代码>。因此,当您使用
range(“ N2”)时。超链接
,您只是删除附加到整个范围的一个一个超链接。为避免这种情况,请循环遍历目的地范围内的所有单元格,并分别为每个单元格附加超链接。例如
,例如,
range(“ n2”)。超链接
仅在此特定单元格中删除超链接。The problem has to do with the fact that
Range("R2").Copy Range("N2:N15")
attaches the hyperlink inR2
to the entire range ofN2:N15
. You can check this by inserting the following code immediately afterwards:Debug.Print (Range("N2:N15").Hyperlinks.Count)
This returns
1
, meaning the entire range only has one hyperlink (instead of 14, as you might be expecting). If then you check this:Debug.Print (Range("N2").Hyperlinks(1).Range.Address)
You will see that it returns
$N$2:$N$15
. Hence, when you useRange("N2").Hyperlinks.Delete
, you are simply deleting the one hyperlink that is attached to the entire range.To avoid this, loop through all the cells in your destination range and attach the hyperlink for each cell individually. E.g.
Now,
Range("N2").Hyperlinks.Delete
will only delete the hyperlink in this particular cell.