Excel中存在一个与超链接和排序相关的已知错误。
KB214328: Hyperlinks are removed or invalid after you sort cells that contain these hyperlinks in Excel
我要指出,在我的情况,我做链接文件的Excel(ProjecWise)之外。
我的工作是将所有超链接作为文本存储在一列中,并使用Excel Hyperlink()函数为另一列中的每一行生成超链接。当您想从外部源(如浏览器)粘贴超链接时,请选择该单元格,然后将链接粘贴到功能区下方的功能框中,而不是直接粘贴到单元格中。这会给你的文本,而不是在单元格中创建超链接对象。
我完全不了解这个问题,但是从我理解Excel处理超链接的方式,单元格中的超链接以某种方式链接到表单对象上的超链接集合。当您对工作表中的行进行排序时,工作表超链接引用开始返回错误的引用。我无法找到工作表超链接引用的唯一'句柄',但注意到h.Parent.Top随着排序而改变。
Public Sub ShowSheetHyperlinks()
' Use this to demonstrate the issue acknowledged here: http://support.microsoft.com/kb/214328
' Add some hyperlinks in a column of a spreadsheet and random values in a column next to it.
' Run this routine. Then sort the values by the first or second column and run this routine again.
' You may have to do this a few times, and/or copy and paste your hyperlink cells to other cells.
' Eventually you will see that the results change after the two columns are sorted.
' (You may not need two columns, but it may help to randomize the sorting.)
Dim h As Hyperlink
Debug.Print "Hyperlinks on " & ActiveSheet.Name & ": " & ActiveSheet.Hyperlinks.Count
For Each h In ActiveSheet.Hyperlinks
' After you sort the list of hyperlinks, you will notice the values in the
' three columns below. I am truncating the address to just see the last 20 characters.
Debug.Print h.TextToDisplay, h.Parent.Top, Right(h.Address, 20)
Next
End Sub
来源
2014-02-21 22:12:20
Ben
非常感谢,通过添加新数据似乎很好。但我遇到了一个奇怪的问题。它适用于“C”和下,但“A”和“B”得到“循环参考警告”。任何想法是什么造成这个?手动输入代码时以及扩展系列时都会发生。 – Zinatic
在添加字母表的其余部分之后,“B”(即“转到:B”超链接)解决了它自己。 “A”仍然被打破,状态栏显示“循环参考:H1”。 (我的清单是在A30:A106,顺便说一句,我改为代码来反映我使用的文档和工作表的名称。) – Zinatic
新代码(公式?)完美工作。非常感谢您的帮助。 – Zinatic