I have written some code that I would like to apply to 3000 csv spreadsheets. Do you know what code I would need to have before and after my code to open every csv file in a folder, apply my code and then save and close the file without converting them to xls files?

Any help whatsoever would be greatly appreciated.



Sounds like you maybe able to use the Dir function to retrieve all the files in the folder and possibly FSO (FileSystemObject) to open, read and process the file. FSO is available by going to "References" and selecting Runtime Scripting, I believe. You may also need to reference Excel's Object Model.

The second option maybe is to use Excel Object Model to process the data in the text files w/out FSO. Excel's object model may provide a way to access the csv file, input the delimiters of the file, if any and then import data into the spreadsheet, much like Excel's Data Import wzd w/out the interface.

In either case, I think you have reference Microsoft Excel Object Model in vb.


managed to find some code on a mountain biking website (vorb.org.nz)

Sub process_data()
' ProcessData Macro
' Macro recorded 28/08/2008 by neelsOnVorb
' Keyboard Shortcut: Ctrl+p
With Application.FileSearch
.LookIn = "H:\My Documents\temp"
.Filename = "*.csv"
If .Execute() > 0 Then
For i = 1 To .FoundFiles.Count
Workbooks.Open Filename:=.FoundFiles(i)
Range("C1").Formula = _
Range("C4").Formula = _
Range("C5").Formula = _
Range("C6").Formula = _
Selection.PasteSpecial Paste:=xlPasteValues, Operation:=xlNone, SkipBlanks _
:=False, Transpose:=False
Application.CutCopyMode = False
ActiveWorkbook.Close (True)
Next i
MsgBox "There were no files found."
End If
End With
End Sub

Thanks anyway

Plz can u tell if U R writing the code in VBA Code window of Excel or Visual Basic.

Also it will be helpful if you give the code u have created to make the changes to those csv spreadsheets. If it is confidential then just specify some outline model of how the code looks.

Will help us to give u a precise solution

Shaik Akthar

This article has been dead for over six months. Start a new discussion instead.