我试图找出一种方法来测试 excel 中的超链接字符串是否指向我们网络上的有效文件。但我有限的 VBA 知识似乎越来越好。
示例:
假设函数“HyperTest”根据超链接有效性返回 TRUE 或 FALSE。
单元格 A1 包含“c:\123.txt”
单元格 B1 包含 "=IF(HyperTest(A1),"是的,该文件是真实的!","看起来有人删除了您的文件。")
我假设模块代码应该类似于:
Public Function HyperTest(hyperpath As String) As Boolean
If [insert test here] Then
return TRUE
Else
return FALSE
End If
End Function
最佳答案
您可以使用 Dir()
function .如果路径不存在,则函数不返回任何内容。由于 bool 值的默认值为 False
,您不需要 Else
陈述。
Public Function HyperTest(hyperpath As String) As Boolean
If Dir(hyperpath) <> vbNullString Then HyperTest = True
End Function
关于用于测试超链接字符串是否引用有效文件的 Excel VBA 模块,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53590478/