'=============================================== this code is placed in a new modul ================================================================================== Function ImportMyCSV() 'this function imports the CSV Dim ColumnsType() As Variant 'declares an empty zero-based array. This is the only variable which MUST be declared MyPath = Application.GetOpenFilename() 'asks the user which CSV file should be imported If MyPath = False Then Exit Function 'if the user aborts the previous question, then exit the whole function ReDim ColumnsType(16383) 'expand the array since excel 2007 and higher has 16384 columns. Excel 2003 is fine with that For i = 0 To 16383 'start a loop with 16383 iterations ColumnsType(i) = 2 'every column should be treated as text (=2) Next i 'repeat the loop and count up variable i If ActiveCell Is Nothing Then 'checks if a workbook is open Workbooks.Add 'if not, it will create a new one Application.Wait DateAdd("s", 1, Now) 'since Excel needs some time to create a new workbook, we have to delay our code ActiveWorkbook.Windows(1).Caption = Dir(MyPath) 'set the workbook caption to the CSV file name to be more user friendly End If With ActiveWorkbook.ActiveSheet.QueryTables.Add(Connection:="TEXT;" & MyPath, Destination:=ActiveCell) 'creates the query to import the CSV. All following lines are properties of this .PreserveFormatting = True 'older cell formats are preserved .RefreshStyle = xlOverwriteCells 'existing cells should be overwritten - otherwise an error can occur when too many columns are inserted! .AdjustColumnWidth = True 'adjust the width of all used columns automatically .TextFileParseType = xlDelimited 'CSV has to be a delimited one - only one delimiter can be true! .TextFileOtherDelimiter = Application.International(xlListSeparator) 'uses system setting => EU countries = ';' and US = ',' .TextFileColumnDataTypes = ColumnsType 'all columns should be treted as pure text .Refresh BackgroundQuery:=False 'this is neccesary so a second import can be done - otherwise the macro can only called once per excel instanz End With 'on this line excel finally starts the import process ActiveWorkbook.ActiveSheet.QueryTables(1).Delete 'deletes the query (not the data) End Function 'we are finished