0

很难解释,但我的照片会很清楚。

我的 Excel 工作表在 a 列中有超链接,链接到要打开的文件,但如何从 l 列中的该文件中获取 lastmodifieddate

示例:a22 链接到文件 vimco,所以该文件的最后修改日期必须在 l22 中

图片在这里

也不是 a 列中的所有行都具有超链接,并且还包含一个空的或未链接的单元格,因此如果是这样,则在 l 列中不必显示任何内容,如果 a 为空白或未链接,则它必须为空白

它可以做一个公式吗?所以我输入 cell =moddate 然后显示日期现在可以了

好的,现在得到代码

Function GetDateTime(myCell As Range) As Date
    Dim myHyperlink As Hyperlink
    Dim Filename As String
    Application.Volatile
    On Error Resume Next
        Set myHyperlink = myCell.Hyperlinks(1)
    On Error GoTo 0
    If Not myHyperlink Is Nothing Then
        Filename = myHyperlink.Address
            'If it is a relative address insert this workbook's path
        If Not (Filename Like "\\*" Or Filename Like "[A-Z]:\*") Then
            Filename = ThisWorkbook.path & "\" & Filename
        End If
        If Dir(Filename, vbNormal) <> "" Then
            GetDateTime = FileDateTime(Filename)
        Else
            GetDateTime = ""
        End If
    Else
        GetDateTime = ""
    End If
End Function

但是现在第二件事,如果链接更改或者我打开我的工作簿或交换表没有更新 getdatetime 的值 - 可以修复吗?

4

1 回答 1

1

您可以在 VBA 中创建自定义函数,并在 Excel 工作表中使用它。为此,您需要FileDateTimeVBA 中的函数来创建如下内容:

Function GetDateTime(r As Range) As Date
GetDateTime = FileDateTime(r.Hyperlinks(1).Address)
End Function

现在您可以将此函数用作普通 Excel 函数,并使用超链接作为参数填充单元格。像这样:=GetDatetime(A1)。如果 A1 中有超链接,它将返回日期。

于 2019-03-05T10:23:30.677 回答