Buonasera a tutti,
grazie alla rete son riuscito a creare una macro che unisce tutti i files *csv presenti nella cartella dove risiede il file Excel a cui è assegnata la macro stessa.
Premesso che i files cvs hanno tutti la medesima riga di intestazione vorrei evitare che questa venga importata tante volte quanti sono i files da importare.
Come dovrei modificare il mio codice?
Grazie anticipatamente
Stefano
Questo il codice
Sub UnisciCSV()
Dim FName As Variant, R As Long, AppPath As String
R = 1
AppPath = Application.ActiveWorkbook.Path & ""
FName = Dir(Application.ActiveWorkbook.Path & "" & "*.csv")
Do While FName <> ""
ImportaCsvFile AppPath & FName, ActiveSheet.Cells(R, 1)
R = ActiveSheet.UsedRange.Rows.Count + 1
FName = Dir
Loop
End Sub
Sub ImportaCsvFile(FileName As Variant, Position As Range)
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;" & FileName _
, Destination:=Position)
.Name = Replace(FileName, ".csv", "")
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = True
.TextFileSemicolonDelimiter = False
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileOtherDelimiter = ";"
.TextFileColumnDataTypes = Array(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, _
1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 _
, 1, 1)
.Refresh BackgroundQuery:=False
End With
End Sub