Question: How can I get a list of files from a directory in VBA? I need some piece of VBA code to list all files from a folder.

Answer: you will need to make a reference to the scripting runtime by going to tools --> references\n\nThen add a listbox and a command button and in the command button insert this code :\n\nDim fso\nDim Folder\n\nSet fso = CreateObject("scripting.filesystemobject")\nSet folder = fso.GetFolder("C:&#92;path")\n\nFor Each File in folder.Files\nListBox1.AddItem File.name\nNext\n\nIf you need more help please post back or email me as this doesnt seem to work wtih code very well.\n\nTake a look here on how to create a reference to the file system object in vba / vbscript :\n\nhttp://computerperformance.co.uk/Logon/VBScript/VBScript_Windows_fso.htm\n\nAs you can see yahoo answers doesnt allow posting of code very well and has commented out my createobject("scripting.filesystemobject")
This question from the Yahoo Q&A forum is categorized in the topic: Education & Reference