2

I want to merge CSV files to one Excel workbook in different sheets.
I want each file in one sheet with the CSV file name as sheet name.

1 Answer 1

1

Create Macro:

Sub ListAllFile3()

 Application.DisplayAlerts = False

Dim strFile As String
strFile = Dir("C:\CSVFile\*.csv", vbNormal)

Do While Len(strFile) > 0       
Set ws = Worksheets.Add
ws.Name = strFile

With Worksheets(strFile).QueryTables.Add(Connection:="TEXT;C:\CSVFile\" & strFile, Destination:=Range"$A$1"))
        .FieldNames = True
        .RowNumbers = False

        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .TextFilePromptOnRefresh = False
        .TextFileStartRow = 1
        .TextFileParseType = xlDelimited
        .TextFileTextQualifier = xlTextQualifierDoubleQuote
        .TextFileConsecutiveDelimiter = False
        .TextFileTabDelimiter = True
        .TextFileSemicolonDelimiter = True
        .TextFileCommaDelimiter = True
        .TextFileSpaceDelimiter = False
        .TextFileColumnDataTypes = Array(1, 1)
        .TextFileTrailingMinusNumbers = True
        .Refresh BackgroundQuery:=False

    End With

strFile = Dir
Loop

 Application.DisplayAlerts = True

End Sub
2
  • could you give me with the loops please.. the complete macro.. I am new to VBA so request some help
    – vijay
    Jun 15, 2013 at 11:33
  • @vijay see again
    – STTR
    Jun 15, 2013 at 13:06

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .