Forum Discussion
wynns2008
Jun 21, 2019Copper Contributor
Batch Import of CSVs into workbook as individual worksheets
Hey Everyone,
I am trying to import a series of csv files into a workbook with worksheets for each csv file. Right now I have figured out how to import all of them into a single worksheet, but I cannot make individuals.
Hope you can help.
4 Replies
- BerndvbatankerIron Contributor
Hi, try this.
Sub ReadCSV()
Dim strFolder As String
Dim strFile As String
Dim wksTab As Worksheet
Dim wkbSource As Workbook
strFolder = ThisWorkbook.Path & "\"
strFile = Dir(strorder & "*.csv")
Do While strFile <> ""
Debug.Print strFile
Workbooks.OpenText Filename:=strFolder & strFile, Semicolon:=True, local:=True
Set wkbSource = ActiveWorkbook
ThisWorkbook.Worksheets.Add
wkbSource.Worksheets(1).UsedRange.Copy Destination:=ThisWorkbook.ActiveSheet.Range("A1")
wkbSource.Close savechanges:=False
strFile = Dir
Loop
End Subor see attachments. Copy all files into a folder an start file start.xlsm
Best regards from germany
Bernd
https://vba-tanker.com/ - https://vba-tanker.com/
- wynns2008Copper Contributor
Berndvbatanker Works great, thanks!
- trishia11271Copper ContributorWhat method do you wish to use? And are all CSV files in one folder? And is it all files in that folder?
If it is one folder of all the files in tht folder the VBA is pretty easy to loop through all the files, importing the data to a new sheet and naming that sheet the same name as the file name.- wynns2008Copper Contributor
trishia11271 All the files are in the same folder, but I am uncertain of the VBA process.