[英]How to find a Excel cell has hyperlink
我在 excel 的 A 列中有数据。我正在遍历列,我需要查找单元格值是否具有超链接初始化。
LR=Activeworkbook.Worksheets("Emp").Range("A65000").End(xlup).Row
for j=1 to LR
if Thisworkbooks.Worksheets("Emp").cells(j,1)="" then 'Logic to find hyperlink
'Function
end if
下一个
正如 Red Hare 在评论中已经提到的那样,最好使用以下内容进行测试:
Dim cell As Range: Set cell = Sheet1.Range("A1") If cell.Hyperlinks.Count > 0 Then ' has a hyperlink Else ' has no hyperlink End If
也就是说,使用单元格的Hyperlinks.Count
属性返回的Hyperlinks object
的Hyperlinks property
,它是一个范围内的超链接集合(在本例中为单个单元格)。 对于单个单元格,Count 属性将仅返回 0 或 1,因此您实际上可以使用
If cell.Hyperlinks.Count = 1 Then ' has a hyperlink
反而。
示例代码
Option Explicit
Sub IdentifyCellsWithHyperlink()
Dim wb As Workbook: Set wb = ThisWorkbook ' workbook containing this code
' If it's not, modify accordingly.
Dim ws As Worksheet: Set ws = wb.Worksheets("Emp")
Dim rg As Range
Set rg = ws.Range("A2", ws.Cells(ws.Rows.Count, "A").End(xlUp))
Dim cell As Range
For Each cell In rg.Cells
If cell.Hyperlinks.Count > 0 Then ' has a hyperlink
Else ' has no hyperlink
End If
Next cell
End Sub
这是可以用来遍历每一行以确定它是否可以设置为超链接的东西。 在不完全理解上下文的情况下,很难找出适合您的可能解决方案的范围......
Private Sub cmdFollowLink_Click()
CreateHyperlink Me,cmdFollowLink, Me!txtSubAddress, _ Me!txtAddress End Sub
Sub CreateHyperlink(ctlSelected As Control, _ strSubAddress As String, Optional strAddress As String) Dim hlk As Hyperlink Select 案例 ctlSelected.ControlType 案例 acLabel, acImage, acCommandButton " strAddress Else.Address = "" End If.SubAddress = strSubAddress.Follow.Address = "".SubAddress = "" End With Case Else MsgBox "控件 '" & ctlSelected.Name _ & "' 不支持超链接。" 结束 Select 结束子
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.