Excel从文件详细信息部分中提取原始信息

时间:2017-03-28 17:37:08

标签: excel vba excel-vba scripting

我正在写VBA以吸引最后保存的"在"属性"下标识的用户一个文件。

我可以访问"上次修改日期" &安培; "上次访问日期"。但我完全不知道如何获得最后保存的#34;数据

请让那里的人知道怎么做! :)

enter image description here

以下是我用于提取"上次修改日期"的当前代码:

Function FileLastModifiedDate(strFullFileName As String)
    Dim fs As Object, f As Object, s As String

    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFile(strFullFileName)

    s = UCase(strFullFileName) & vbCrLf
    s = f.datelastmodified
    FileLastModifiedDate = s

    Set fs = Nothing: Set f = Nothing

End Function

1 个答案:

答案 0 :(得分:0)

以下Function适用于 Excel Word 文件:

Function FileLastSavedBy(strFullFileName As String)

Dim fs As Object, f As Object, s As String
Dim wb As Workbook
Dim wordApp As Object
Dim wordDoc As Object

Application.ScreenUpdating = False
Application.DisplayAlerts = False

If UCase(strFullFileName) Like "*XLS*" Then ' <-- check Excel file    
    Set fs = CreateObject("Scripting.FileSystemObject")
    Set f = fs.GetFile(strFullFileName)

    Set wb = Workbooks.Open(f)
    FileLastSavedBy = wb.BuiltinDocumentProperties("Last Author")
    wb.Close False
    Set fs = Nothing
    Set f = Nothing

ElseIf UCase(strFullFileName) Like "*DOC*" Then ' <-- check Word file
    Set wordApp = CreateObject("word.Application")
    Set wordDoc = wordApp.Documents.Open(strFullFileName)
    FileLastSavedBy = wordDoc.BuiltinDocumentProperties("Last Author")

    wordDoc.Close False
    Set wordDoc = Nothing
    wordApp.Quit
    Set wordApp = Nothing
End If

Application.ScreenUpdating = False
Application.DisplayAlerts = False

End Function

子代码 (测试功能)

Sub testFunc()

Dim a As String
a = FileLastSavedBy("C:\Users\Shai\Desktop\North Carolina.xlsx") '<-- modify this to your file name and path (Excel File)

a = FileLastSavedBy("C:\Users\Shai\Desktop\GanName.Docx") '<-- modify this to your word document name and path (Word document)


MsgBox a

End Sub