Forum Thread

Excel VBA file handling help

Dr. J 25,043 3,353 May 2, 2016 at 07:29 AM
I have a template Excel file that has a bunch of code/macros in it. What I need is to automate the following:
- Open a CSV in the same directory (there are any number of CSV's in the directory but all have the name "TEST X.CSV" where X is 1, 2, etc)
- Copy the first Y columns (Y is specified in the template workbook) to a worksheet in the template workbook ("Raw Data") starting at column B
- Run a Macro (pre-written)
- Save As the template XLSXM to a file with the same name as the CSV (e.g. TEST 1.XLSXM, etc)
- Loop through all the CSV files

Y will remain the same for all the CSV files.

I can do a lot with formulas and macros but file handling is not my forte to say the least.



Sign up for a Slickdeals account to remove this ad.

Joined Jul 2005
Toadally Irrelephant
7,615 Posts
1,199 Reputation
Need to know what version/edition of Excel and VBA you're running. Check Example 5, specifically.

The FileSystemObject (FSO) is your friend. You create an FSO object, use it to create a File object, and open and work with that file.
Reply Helpful Comment? 0 0
Last edited by VorlonFrog May 2, 2016 at 06:23 PM
Quote from serra View Post :
stoopid serra.
Quote from slickdeals View Post :
How did I end up here...
Page 1 of 1
Join the Conversation
Add a Comment
Copyright 1999 - 2016. Slickdeals, LLC. All Rights Reserved. Copyright / Infringement Policy  •  Privacy Policy  •  Terms of Service  •  Acceptable Use Policy (Rules)  •  Interest-Based Ads
Link Copied to Clipboard