2

I have a macro that reads out external file properties like date created. The file from where I read is stored on a server. Unfortunately the date returned is not the correct one when running the macro the first time. Only when I open the file or when I run the macro several times, the correct updated date created is returned.

Does anyone have an idea how to solve that issue except from opening the file or looping through until the date is correct?

Here is the code:

strFilename = "<FILENAME>"

Workbooks.Open strFilename
Workbooks("strFilename").Close

Set oFS = CreateObject("Scripting.FileSystemObject")

lastcreatedLTVfile = CDate(Format(oFS.GetFile(strFilename).DateCreated, "dd.mm.yyyy"))
R3uK
  • 14,417
  • 7
  • 43
  • 77
  • What means "not the correct one"? What exactly is returned? – Axel Richter Aug 17 '15 at 08:48
  • 2
    `Workbooks("strFilename").Close` should be `Workbooks(strFilename).Close`. I don't see how that solves your issue but needs fixing regardless. Also, why are you taking a date, converting it to a string, and then casting it back to a date again? – Bond Aug 17 '15 at 09:06
  • When I open the file and close the file, the date is updated and I can get the right one. But the opening and closing takes time... – Sebastian Walter Aug 18 '15 at 06:56
  • I use a string because the formatting of the date returned is not the one I need, therefore I need to format it first and then convert it into a date again – Sebastian Walter Aug 18 '15 at 06:56

1 Answers1

0

Do you want DateCreated or do you actually want DateLastModified? In your question you say "correct updated date" so I guess you should be using DateLastModified.

ChipsLetten
  • 2,923
  • 1
  • 11
  • 28