Hello forum,
I have a question i hope some of you might be able to help me with.

I have a document where i would like to import a CSV file.
I would like to be able to push a button "Import CSV" and get a browse window where i can locate the file i want to import and then import it.

I made a recording of a macro where i use the import CSV function and then adjusts the rows/colums and was hoping to use this after the file is selected.

The macro inserts the csv in to the excel, deletes an column that empty, removes the 4 first lines in the csv file and renames the column title.

Sub Import_CSV()
'
' Import_CSV Makro
'

'
    ActiveWorkbook.Queries.Add Name:="Import CSV", _
        Formula:= _
        "let" & Chr(13) & "" & Chr(10) & "    Kilde = Csv.Document(File.Contents(""G:\PATH\THE_FILE_I_WANT_TO_IMPOER.csv""),[Delimiter="","", Columns=13, Encoding=1252, QuoteStyle=QuoteStyle.None])," & Chr(13) & "" & Chr(10) & "    #""Endret type"" = Table.TransformColumnTypes(Kilde,{{""Colu" & _
        "mn1"", type text}, {""Column2"", type text}, {""Column3"", type text}, {""Column4"", type text}, {""Column5"", type text}, {""Column6"", type text}, {""Column7"", type text}, {""Column8"", type text}, {""Column9"", type text}, {""Column10"", type text}, {""Column11"", type text}, {""Column12"", type text}, {""Column13"", type text}})," & Chr(13) & "" & Chr(10) & "    #""Fjernede kolonner"" = T" & _
        "able.RemoveColumns(#""Endret type"",{""Column13""})," & Chr(13) & "" & Chr(10) & "    #""Øverste rader fjernet"" = Table.Skip(#""Fjernede kolonner"",4)," & Chr(13) & "" & Chr(10) & "    #""Kolonner med nye navn"" = Table.RenameColumns(#""Øverste rader fjernet"",{{""Column1"", ""TIMESLOT""}, {""Column2"", ""NAV1 SSR""}, {""Column3"", ""NAV2 SSR""}, {""Column4"", ""DME1 SSR""}, {""Column5"", ""TCN1 SSR""}, {""Column6"", """ & _
        "TCN2 SSR""}, {""Column7"", ""REF DIST""}, {""Column8"", ""REF AZ 360_M""}, {""Column9"", ""REF EL""}, {""Column10"", ""HDG_T""}, {""Column11"", ""ROLL ANGLE""}, {""Column12"", ""PITCH ANGLE""}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & "    #""Kolonner med nye navn"""
    ActiveWorkbook.Worksheets.Add
    With ActiveSheet.ListObjects.Add(SourceType:=0, Source:=Array( _
        "OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=Import CSV;Extended Properties=""" _
        , """"), Destination:=Range("$A$1")).QueryTable
        .CommandType = xlCmdSql
        .CommandText = Array( _
        "SELECT * FROM [Import CSV]")
        .RowNumbers = False
        .FillAdjacentFormulas = False
        .PreserveFormatting = True
        .RefreshOnFileOpen = False
        .BackgroundQuery = True
        .RefreshStyle = xlInsertDeleteCells
        .SavePassword = False
        .SaveData = True
        .AdjustColumnWidth = True
        .RefreshPeriod = 0
        .PreserveColumnInfo = True
        .ListObject.DisplayName = "_Import CSV"
        .Refresh BackgroundQuery:=False
    End With

End Sub
Im not locked in to this solution. If you know of a better way where i can click a button, get a browse window to select my file and import the contens in to my worksheet im all ears :-) the CSV file differs in rows. one fil might have 4000 rows another might have 15000 rows but the 12 columns will always be the same.

Best regards
Joachim