Link to home
Create AccountLog in
Avatar of rrhandle8
rrhandle8Flag for United States of America

asked on

Find creation date of Excel Workbook

I am opening Excel workbooks use VBA in Access.  I want to get the original creation date of the workbook, but what I am getting is the date is was moved to the current folder.


Dim WkBk As Excel.Workbook
Set WkBk = ExcelApp.Workbooks.Open(filename:=WbkPathName)
WkBk.BuiltinDocumentProperties("Creation Date")

Open in new window



I tried using this, but it causes an error:

WkBk.BuiltinDocumentProperties.items("Creation Date").Value

Open in new window



Access 2003
Excel 2010
Avatar of Flyster
Flyster
Flag of United States of America image

If it's the active workbook, try this:

ActiveWorkbook.BuiltinDocumentProperties("Creation Date")

Flyster
Avatar of rrhandle8

ASKER

ActiveWorkbook.BuiltinDocumentProperties("Creation Date") also returns today's date.  Today is the day I saved it to my computer.
The original creation date is back in August, and can be seen on the Statistics tab of the property box.
CORRECTION -- The date on the Statistics tab is today's date.  The date on the general tab is back in August.
I already tried that.  Didn't work.
I have discovered the only way to get the original creation date is to use the FileSystemObject.

Option Compare Database
Option Explicit
Function getCreationDate(strCompleteFilePath As String) As Date
    Dim objFileSystem       As Object
    Dim objFile             As Object
    Set objFileSystem = CreateObject("Scripting.FileSystemObject")
    If objFileSystem.FileExists(strCompleteFilePath) Then
        Set objFile = objFileSystem.GetFile(strCompleteFilePath)
        getCreationDate = objFile.DateCreated
    Else
        MsgBox "The specified file '" & strCompleteFilePath & "' does not exist.",    vbInformation, "Creation Date"
    End If
    Set objFile = Nothing
 End Function
 Function getOpnWbkCreationDate(wbkOpened As Workbook) As Date
     getOpnWbkCreationDate = wbkOpened.BuiltinDocumentProperties("Creation Date")
 End Function
 Sub ExecuteFunc()
     MsgBox getCreationDate(ThisWorkbook.FullName)
    MsgBox getOpnWbkCreationDate(ThisWorkbook)
End Sub

Open in new window

I correct myself again.  Even using the FSO, sometimes the original creation day is captured, other times it is not.  Very confusing.
ASKER CERTIFIED SOLUTION
Avatar of Farzad Akbarnejad
Farzad Akbarnejad
Flag of Iran, Islamic Republic of image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
There was no answer to this problem.
rrhandle8,
If you don't get your proper solution you can request for attention to this question and get points refund.

-FA