How can I download and import a CSV file into Excel using VBA script?

Posted by:

How can I download and import a CSV file into Excel using VBA script?

Download and import a CSV file into Excel using VBA script? If it is a one-off and not too many files, frankly I would open them manually from the Excel desktop. It handles CSV.

Download and import a CSV file into Excel using VBA script

If you want to do it programmatically, you can use OPEN, GET, PUT and related commands to access the files record by record. You can break it out into an array with SPLIT on commas. You can take the final array and set it as the. Value property of a defined range on the appropriate worksheet. There are many ways to proceed, and some are more efficient. This was my oldest and easiest to find. Be sure to close the files you open for PUT or similar operations.

If you want to automate the identification and handling of the csv file population, you can use FileSystemObject. Remember the crosswalk between the FSO and the Excel Application Object workbook structure when you manipulate the workbooks.

If you really want to get fancy, you can write a custom object structure that contains all of those operations. See “custom objects” in VBA references. They are actually huge fun. You can make games.

0

Add a Comment