首页 > 解决方案 > excel超链接函数到变量

问题描述

我有很多具有超链接功能的单元格。一个例子:A1=HYPERLINK("T:\projekt1\61VWAus.xlsx";"61VWAus.xlsx" )。我需要遍历每个单元格并检查每个超链接是否是有效文件。如何"T:\projekt1\61VWAus.xlsx"从公式值中获取指向变量的超链接?我是否必须使用字符串操作来获取它,或者是否有任何直接功能可以仅获取超链接?谢谢

标签: excelvba

解决方案


我找到了解决方案:

Function check_hyperlink(rng As Range) As Boolean
Dim oFSO As Object
Dim str_Hyperlink As String
Dim exists As Boolean
Dim str_form As String
Dim arr_str_form As Variant

Set oFSO = CreateObject("Scripting.FileSystemObject")
    str_form = rng.Cells(1, 1).Formula
    
    If Left(str_form, 10) = "=HYPERLINK" Then
        arr_str_form = Split(str_form, Chr(34))
        str_Hyperlink = arr_str_form(1)
        exists = oFSO.FileExists(str_Hyperlink)
        
        If exists Then
            check_hyperlink = True
        Else
            check_hyperlink = False
        End If
    Else
        check_hyperlink = False
    End If
End Function

推荐阅读