如何查找Excel单元格中有超链接

zdwk9cvp  于 2022-11-26  发布在  其他
关注(0)|答案(2)|浏览(650)

我在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

下一个

n53p2ov0

n53p2ov01#

这里有一些东西可以用来运行通过每一行,以确定它是否可以设置为一个超链接。有点难以弄清楚什么可能的解决方案的范围是什么,将为您工作没有充分了解上下文...

Private Sub cmdFollowLink_Click()

创建超链接Me!cmd跟随链接,Me!txtSubAddress,_ Me!txtAddress结束子
子创建超链接(ctlSelected As Control,_ strSubAddress As String,可选strAddress As String)Dim hlk As超链接选择大小写ctlSelected.ControlType大小写acLabel,acImage,acCommandButton设置hlk = ctl已选定。如果不缺少hlk则使用超链接(strAddress)则.地址= strAddress否则.地址=“”结束如果.子地址= strSubAddress .跟随.地址=“”.子地址=“”End With Case Else MsgBox“控件'”& ctlSelected.Name _ &“'不支持超链接。”End Select End Sub

zd287kbt

zd287kbt2#

  • As Red Hare already mentioned in the comments, it is best tested with something like the following:
Dim cell As Range: Set cell = Sheet1.Range("A1")
If cell.Hyperlinks.Count > 0 Then ' has a hyperlink
Else ' has no hyperlink
End If

that is, using the Hyperlinks.Count property of the Hyperlinks object returned by the cell's Hyperlinks property which is a collection of hyperlinks in a range (in this case, a single cell). For a single cell, the Count property will return only 0 or 1 so you could actually use

If cell.Hyperlinks.Count = 1 Then ' has a hyperlink

instead.

Example Code

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

相关问题