Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8839661
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T10:17:10+00:00 2026-06-14T10:17:10+00:00

I need to loop through a folder containing many excel files and extract the

  • 0

I need to loop through a folder containing many excel files and extract the file name and creation time to a text file. By creation time, I mean the time the file was originally created rather than the time it was created on my system.

The following code works, but gives me the wrong time. I think FileDateTime is the wrong command, but after an hour of desperate googling I haven’t been able to find the correct one.

Thanks in advance for the help!

Sub CheckFileTimes()
    Dim StrFile As String
    Dim thisBook As String
    Dim creationDate As Date
    Dim outputText As String
    Const ForReading = 1, ForWriting = 2
    Dim fso, f

'set up output file
   Set fso = CreateObject("Scripting.FileSystemObject")
   Set f = fso.OpenTextFile("C:\TEST.txt", ForWriting, True)

'open folder and loop through
    StrFile = Dir("c:\HW\*.xls*")
    Do While Len(StrFile) > 0
'get creation date
       creationDate = FileDateTime("C:\HW\" & StrFile)
'get filename
       thisBook = StrFile
       outputText = thisBook & "," & creationDate
'write to output file
       f.writeLine outputText
'move to next file in folder
       StrFile = Dir
    Loop
    f.Close
End Sub
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-14T10:17:11+00:00Added an answer on June 14, 2026 at 10:17 am

    Welp, I found the answer. Looks like I wasn’t too far off (though I don’t think this is anywhere near optimal). Thanks to everyone who took a look at this.

    Sub CheckFileTimes3()
        Dim StrFile, thisBook, outputText As String
        Dim creationDate As Date
        Dim fso, f
        Dim oFS As Object
        Const ForReading = 1, ForWriting = 2
    
        Application.ScreenUpdating = False
        Application.DisplayAlerts = False
        Application.EnableEvents = False
    
        'open txt file for storing results
       Set fso = CreateObject("Scripting.FileSystemObject")
       Set f = fso.OpenTextFile("C:\TEST.txt", ForWriting, True)
    
        'loop through all files in given folder
        StrFile = Dir("c:\HW\*.xls*")
        Do While Len(StrFile) > 0
           Workbooks.Open Filename:="C:\HW\" & StrFile
           creationDate = ActiveWorkbook.BuiltinDocumentProperties("Creation Date")
           thisBook = StrFile
           outputText = thisBook & "," & creationDate
           'MsgBox outputText
           f.writeLine outputText
           ActiveWorkbook.Close
           StrFile = Dir
        Loop
        f.Close
    
        Application.ScreenUpdating = True
        Application.DisplayAlerts = True
        Application.EnableEvents = True
    End Sub
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have about 5000 html files in a folder. I need to loop through
i have the following code ..i need to loop through end of the file
I have many text files in a folder. What I can do now is
I need to loop through a List of Dictionaries List<Dictionary<string,string>> to populate a DataTable.
I need to loop through a set of 2-dimensional array of hidden input fields
I need to loop through each day of the week (monday tues...) and compare
I have a nested JSON object that I need to loop through, and the
Okay so this is a bit complex but I need to loop through this
my heading kinda explains the problem. I need to loop through multiple ul tags
I need to periodically loop through links in my PHP database to check whether

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.