Access to embedded information about document properties without opening a workbook

I use the code below to get the generated workbook date.

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 the file was created in the directory.
If you copy the file to another folder, the above will return this time and date, they were copied (created).

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

 Dim wb As Workbook Set wb = Workbooks.Open(mfile) '/* same string as above */ Debug.Print wb.BuiltinDocumentProperties("Creation Date") 

The above does returns the original date when the file was created.

Now I have hundreds of files sitting in a directory where I need to get the original creation date.
I can, of course, use the above and browse the files, but opening and closing all this from a shared disk takes some time. So I was wondering if I can get BuiltinDocumentProperties without opening the file (s), for example, using the first code, which is much faster and easier to manage.

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

+5
source share
1 answer

Try something like this. A key is a 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 
+3
source

Source: https://habr.com/ru/post/1274942/


All Articles