ich hab -mal wieder- ein Syntaxproblem.
Ich öffne per Marco verschiedene CSV-Datei, formatiere diese ein bischen und möchte eine Sortierung einfügen.
Ich habe das per Macrorecorder aufgezeichnet und nun funktioniert das nur mit der Datei, die ich zur Erstellung des Macro's genommen habe.
Wie kann ich dass jetzt anpassen, damit das mit jeder beliebigen Datei, die ich mit dem Macro öffne, funktioniert.?!?!?
Sub CSV_Einlesen()
' CSV_Einlesen Makro
ChDir "d:\daten\Microsoft Office Excel 2007"
Dim strPfad As String
strPfad = Application.GetOpenFilename("CSV-Dateien (*.csv), *.csv")
If strPfad CStr(False) Then
Workbooks.OpenText Filename:= _
strPfad, Origin _
:=xlWindows, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=True, _
Comma:=True, Space:=False, Other:=False, FieldInfo:=Array(Array(1, 1), _
Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1)), TrailingMinusNumbers:=True
End If
Range("A2").Select
ActiveWindow.FreezePanes = True
Rows("1:1").Select
Selection.Font.Bold = True
With Selection
.HorizontalAlignment = xlCenter
End With
Range("A1:E1").Select
'Range("E1").Activate
Selection.AutoFilter
Cells.Select
Cells.EntireColumn.AutoFit
Range("A1").Select
ActiveWorkbook.Worksheets("csv-report.2011-11-09.13-39-05").Sort.SortFields.Clear
ActiveWorkbook.Worksheets("csv-report.2011-11-09.13-39-05").Sort.SortFields.Add _
Key:=Range("A2:A3312"), SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("csv-report.2011-11-09.13-39-05").Sort.SortFields.Add _
Key:=Range("E2:E3312"), SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
ActiveWorkbook.Worksheets("csv-report.2011-11-09.13-39-05").Sort.SortFields.Add _
Key:=Range("C2:C3312"), SortOn:=xlSortOnValues, Order:=xlAscending, _
DataOption:=xlSortNormal
With ActiveWorkbook.Worksheets("csv-report.2011-11-09.13-39-05").Sort
.SetRange Range("A1:F3312")
.Header = xlYes
.MatchCase = False
.Orientation = xlTopToBottom
.SortMethod = xlPinYin
.Apply
End With
End Sub