Need to create a CSV / Excel file of file listing in a specified windows directory

Posted on 2004-11-16
Last Modified: 2010-05-02
A beginners question really: could someone point to any controls or code or suggestions on how I can read a list of files from a specified windows directory into a csv (or similar) file which I would then like to read into Excel?

Many thanks
Question by:Rmocherla
    LVL 5

    Accepted Solution

    Try something like...

    Private Sub Command1_Click()
    Dim myFile As String
    Dim parDir As String
    Dim parFile As String

    parDir = "c:\"
    parFile = Dir(parDir, vbNormal)
    myFile = "c:\outputfile.txt"
    Open myFile For Output As 1
    While parFile <> vbNullString
        Print #1, parFile
        parFile = Dir

    Close 1

    End Sub

    This will create a text file which can be read into Excel, Word etc etc.

    Author Comment

    Worked first time....many thanks

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    What Should I Do With This Threat Intelligence?

    Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

    Introduction In a recent article ( for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
    If you have ever used Microsoft Word then you know that it has a good spell checker and it may have occurred to you that the ability to check spelling might be a nice piece of functionality to add to certain applications of yours. Well the code that…
    As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
    This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now