| Posted at 11:48 AM on January 05, 2009 |
Twitter user, v1p1n, asked ... "I have three csv files (comma seperated). I want to merge these csv files to a single xls files with 3 csv files in 3 tabs of the xls. Please let me know how i can do this..... "
Here's some code to get you started, this will merge 3 CSV files (FILE1,FILE2 and FILE3) into a single sheet. You'll need to modify strFilePath to the path the the CSV files...
Sub CSVFiles()
MergeCSVFile "FILE1.CSV", "Sheet1"
MergeCSVFile "FILE2.CSV", "Sheet2"
MergeCSVFile "FILE3.CSV", "Sheet3"
End Sub
Sub MergeCSVFile(strCSVName As String, strSheetID As String)
strFilePath = "c:\temp\"
Workbooks.Open Filename:=strFilePath & strCSVName
Windows(strCSVName).Activate
Cells.Select
Selection.Copy
Windows("Book1").Activate
Sheets(strSheetID).Select
Cells.Select
ActiveSheet.Paste
Range("A1").Select
End Sub
Categories: VBA (or how to go insane)