Hallo,
ich möchte eine .csv Datei automatisch mit einem Makro öffnen lassen.
Ich weiß nur nicht wie ich den Speicherort der Datei variable machen kann, also wenn ich den Makro starte, dass eine Auswahl geöffnet wird, welche Datei ich öffnen möchte.
Das Makro um eine fixe Datei zu öffnen:
Sub Makro1()
'
' Makro1 Makro
'
'
ActiveWorkbook.Queries.Add Name:="meas2", Formula:= _
"let" & Chr(13) & "" & Chr(10) & " Quelle = Csv.Document(File.Contents(""E:\Test\meas2.csv""),[Delimiter="","", Columns=14, Encoding=1252, QuoteStyle=QuoteStyle.None])," & Chr(13) & "" & Chr(10) & " #""Typ ändern"" = Table.TransformColumnTypes(Quelle,{{""Column1"", 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}, {""Column14"", type text}})" & Chr(13) & "" & Chr(10) & "in" & Chr(13) & "" & Chr(10) & " #""Typ ändern"""
ActiveWorkbook.Worksheets.Add
With ActiveSheet.ListObjects.Add(SourceType:=0, Source:= _
"OLEDB;Provider=Microsoft.Mashup.OleDb.1;Data Source=$Workbook$;Location=meas0;Extended Properties=""""" _
, Destination:=Range("$A$1")).QueryTable
.CommandType = xlCmdSql
.CommandText = Array("SELECT * FROM [meas0]")
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.BackgroundQuery = True
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.PreserveColumnInfo = True
.ListObject.DisplayName = "meas2"
.Refresh BackgroundQuery:=False
End With
Range("F14").Select
End Sub
Ich hoffe, dass mir jemand helfen kann.
Grüße
JOJO
|