Imports multiple CSVs found in a folder into worksheets of active workbook
This one was created with Bing AI (ChatGPT-4) as testing it.
Another way was Import_CSVs
So, this is not my work, it is the robot (is it though?)
Sub ImportCSVs()
Dim strPath As String
Dim strFile As String
'Change the path to the folder containing your CSV files
strPath = "C:\CSVFolder\"
strFile = Dir(strPath & "*.csv")
Do While Len(strFile) > 0
With ActiveWorkbook.Worksheets.Add
With .QueryTables.Add(Connection:="TEXT;" & strPath & strFile, Destination:=.Range("A1"))
.TextFileParseType = xlDelimited
.TextFileCommaDelimiter = True
.Refresh BackgroundQuery:=False
End With
'Rename the worksheet to the name of the CSV file (without extension)
.Name = Left(strFile, InStrRev(strFile, ".") - 1)
End With
'Get next CSV file in folder
strFile = Dir()
Loop
End Sub
Dim strPath As String
Dim strFile As String
'Change the path to the folder containing your CSV files
strPath = "C:\CSVFolder\"
strFile = Dir(strPath & "*.csv")
Do While Len(strFile) > 0
With ActiveWorkbook.Worksheets.Add
With .QueryTables.Add(Connection:="TEXT;" & strPath & strFile, Destination:=.Range("A1"))
.TextFileParseType = xlDelimited
.TextFileCommaDelimiter = True
.Refresh BackgroundQuery:=False
End With
'Rename the worksheet to the name of the CSV file (without extension)
.Name = Left(strFile, InStrRev(strFile, ".") - 1)
End With
'Get next CSV file in folder
strFile = Dir()
Loop
End Sub
None
Views 113
Downloads 36
CodeID
DB ID
ANmarAmdeen
610
Revisions
v1.0
Monday
March
20
2023