简体   繁体   中英

Access built-in document properties information without opening the workbook

I am using below code to get the created date of a workbook.

Dim mFile As String

mFile = "C:\User\User.Name\Test\Test.xlsx"
Debug.Print CreateObject("Scripting.FileSystemObject").GetFile(mFile).DateCreated

However to my surprise, this returns the date when the file is created in the directory.
If you copy the file to another folder, above will return that time and date it was copied (created).

To actually get the original created date , I tried using BuiltinDocumentProperties method.
Something like below:

Dim wb As Workbook
Set wb = Workbooks.Open(mfile) '/* same string as above */

Debug.Print wb.BuiltinDocumentProperties("Creation Date")

Above does return the original date the file was actually created .

Now, I have hundreds of file sitting in a directory that I need to get the original creation date.
I can certainly use above and look over the files, but opening and closing all of it from a shared drive takes some time. So I was wondering, if I can get the BuiltinDocumentProperties without opening the file(s) like using the first code above which is a lot faster and easier to manage.

If you somebody can point me to a possible solution, that would be great.

Try something like this. The key is the special DSO object.

Imports Scripting
Private Sub ReadProperties()
    Dim pathName As String = "C:\yourpathnamehere"
    Dim Fso As FileSystemObject = New Scripting.FileSystemObject
    Dim fldr As Folder = Fso.GetFolder(pathName)
    Dim objFile As Object = CreateObject("DSOFile.OleDocumentProperties")

    Dim ResValue As String = Nothing
    For Each f In fldr.Files
        Try
            objFile.Open(f)
            ResValue = objFile.SummaryProperties.DateCreated
            ' Do stuff here
            objFile.Close
        Catch ex As Exception
            'TextBox1.Text = ex.Message
        End Try

        Application.DoEvents()
    Next
End Sub

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM