Import CSV

Submitted by Masaru Kaji of Kobe-City, Japan. Masaru provides Excel Consultation through Colo's Junkroom (www.interq.or.ip/sun/puremis/colo/).

If you find yourself importing a lot of CSV files and then having to go back and delete them, this program is for you. It quickly opens up a CSV in Excel and deletes the original file: Option Base 1

Sub OpenLargeCSVFast()

Dim buf(1 To 256) As Variant Dim i As Long

Const strFilePath As String = "C:\temp\Test.CSV" 'Change here Dim strRenamedPath As String strRenamedPath = Split(strFilePath, ".")(0) & "txt"

With Application

.ScreenUpdating = False .DisplayAlerts = False End With

'Setting an array for FieldInfo to open CSV For i = 1 To 256

Next

Name strFilePath As strRenamedPath

Workbooks.OpenText Filename:=strRenamedPath, DataType:=xlDelimited, Comma:=True, FieldInfo:=buf

Erase buf

ActiveSheet.UsedRange.Copy ThisWorkbook.Sheets(1).Range("A1") ActiveWorkbook.Close False Kill strRenamedPath With Application

.ScreenUpdating = True .DisplayAlerts = True End With End Sub

0 0

Post a comment