Laufzeitfehler '1004' bei Makro mit Pivot
06.07.2006 07:10:11
lukex2000
Wenn ich versuche das Makro im gleichen Dokument oder in anderen Mappen auszuführen, bricht das Makro jedesmal mit dem Fehler:
Laufzeitfehler '1004':
Die PivotFields-Eigenschaft des PivotTable-Objektes kann nicht zugeordnet werden.
ab.
Im folgenden der Code mit der markierten (%%% ... %%%) Abbruchstelle.
Sub Makro1()
' Makro1 Makro
' Makro am 04.07.2006 von Lühe aufgezeichnet
' Tastenkombination: Strg+w
With ActiveSheet.QueryTables.Add(Connection:= _
"TEXT;C:\Dokumente und Einstellungen\lühe\Desktop\csv Projekt\Istwerte0.csv", _
Destination:=Range("A1"))
.Name = "Istwerte0"
.FieldNames = True
.RowNumbers = False
.FillAdjacentFormulas = False
.PreserveFormatting = True
.RefreshOnFileOpen = False
.RefreshStyle = xlInsertDeleteCells
.SavePassword = False
.SaveData = True
.AdjustColumnWidth = True
.RefreshPeriod = 0
.TextFilePromptOnRefresh = False
.TextFilePlatform = 850
.TextFileStartRow = 1
.TextFileParseType = xlDelimited
.TextFileTextQualifier = xlTextQualifierDoubleQuote
.TextFileConsecutiveDelimiter = False
.TextFileTabDelimiter = False
.TextFileSemicolonDelimiter = True
.TextFileCommaDelimiter = False
.TextFileSpaceDelimiter = False
.TextFileColumnDataTypes = Array(1, 1, 1, 9, 9)
.TextFileTrailingMinusNumbers = True
.Refresh BackgroundQuery:=False
End With
Columns("A:C").Select
Selection.Sort Key1:=Range("A1"), Order1:=xlAscending, Header:=xlGuess, _
OrderCustom:=1, MatchCase:=False, Orientation:=xlTopToBottom, _
DataOption1:=xlSortNormal
ActiveWorkbook.PivotCaches.Add(SourceType:=xlDatabase, SourceData:= _
"Tabelle1!C1:C3").CreatePivotTable TableDestination:="", TableName:= _
"PivotTable1", DefaultVersion:=xlPivotTableVersion10
ActiveSheet.PivotTableWizard TableDestination:=ActiveSheet.Cells(3, 1)
ActiveSheet.Cells(3, 1).Select
Charts.Add
ActiveChart.Location Where:=xlLocationAsNewSheet
With ActiveChart.PivotLayout.PivotTable.PivotFields("TimeString") %%% Abbruchstelle %%%
.Orientation = xlRowField
.Position = 1
End With
With ActiveChart.PivotLayout.PivotTable.PivotFields("VarName")
.Orientation = xlColumnField
.Position = 1
End With
ActiveChart.PivotLayout.PivotTable.AddDataField ActiveChart.PivotLayout. _
PivotTable.PivotFields("VarValue"), "Anzahl von VarValue", xlCount
ActiveChart.Axes(xlCategory).Select
With ActiveChart.Axes(xlCategory)
.CrossesAt = 1
.TickLabelSpacing = 100
.TickMarkSpacing = 1
.AxisBetweenCategories = True
.ReversePlotOrder = False
End With
ActiveChart.PivotLayout.PivotTable.PivotFields("Anzahl von VarValue").
Function _
= xlMax
ActiveChart.PlotArea.Select
ActiveChart.ChartType = xlLine
ActiveWorkbook.ShowPivotTableFieldList = False
Application.CommandBars("PivotTable").Visible = False
End
Sub
Kennt jemand die Antwort?