Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

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

Posted on 2004-11-16
2
Medium Priority
?
173 Views
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
0
Comment
Question by:Rmocherla
2 Comments
 
LVL 5

Accepted Solution

by:
ajgilbert earned 2000 total points
ID: 12592096
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
Wend

Close 1

End Sub

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

Author Comment

by:Rmocherla
ID: 12592291
Worked first time....many thanks
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
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…
Suggested Courses
Course of the Month21 days, 2 hours left to enroll

810 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