How to get file creation date/time?

I

Ian

Using Word97.

I know there has to be a very simple answer, but I can't find it any
place: What VBA code do I need to read the creation date/time of the
ActiveDocument? That is, the information shown by File > Properties >
Statistics > Created.
 
M

Martin Seelhofer

Hi Ian

This might be what you're looking for:

ActiveDocument.BuiltInDocumentProperties(wdPropertyTimeCreated)


Cheers,
Martin
 
M

macropod

Hi Ian,

if you only need this to display in the document itself, you could simply
use a CREATEDATE field at the appropriate point ... no vba required, though
you could equally insert such a field using vba.

Cheers
 
I

Ian

Hi macropod.

Understood. But I need to find the create date programmatically, as I am
incorporating the date into an automatically built filename.

However, a thought has just occurred to me. On this system, the create
date text string looks something like "30/01/04 16:30:00". That is,
day/month/year. I was simply going to extract characters 1-2 for day,
4-5 for month and 7-8 for year. But obviously this will not work in a
different locale where, for example, the date format may be
month/day/year.

So how can I unambiguously extract the day, month and year from the
create date string, in any locale? I suspect I may need code something
like this:

~~~~~~~~~~~~~~
If locale = dmy then
day = mid$(createdate, 1, 2) ' day is in chars 1-2
month = mid$(createdate, 4, 2)
year = mid$(createdate, 7, 2)
Else
day = mid$(createdate, 4, 2) ' day is in chars 4-5
month = mid$(createdate, 1, 2)
year = mid$(createdate, 7, 2)
EndIf

~~~~~~~~~~~~~~~

If so, how do I discover the locale?
 
G

Guest

You'll probably want to assign the creation date to a date variable then use
the format function. For example,

Dim MyDate as Date, MyFile as String
MyDate = ActiveDocument.BuiltInDocumentProperties(wdPropertyTimeCreated)
MyFile = Format(MyDate,"mmddyyyy")

Hope this helps.

-Brian
 
M

Martin Seelhofer

Hey there again,

As Brian pointed out, using Mid and doing all that yourself is quite
a bit of work (and might even fail on systems having other regional
settings). However, apart from the Format-approach, there are
also some other predefined VBA-functions which might help you out:

Day(...)
Month(...)
Year(...)

Minute(...)
Hour(...)
Second(...)

All applicable to any date values, including the file creation time :)


Cheers,
Martin
 
I

Ian

Thanks Martin. I just found the pre-defined functions you mentioned in
the VBA Help (I must use this more often -- when I started learning VBA
I found the Help information was often very UNhelpful, so got out of the
habit of using it).
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top