尝试创建宏时,请始终将其显示为错误1004 Unable to get the PivotFields property of the PivotTable class
,但我不确定代码有什么问题,因此将不胜感激。目的是获取创建的数据透视表,以格式化日期和每天的显示计数。
Columns("A:A").Select
Selection.TextToColumns Destination:=Range("Outlook[[#Headers],[Created]]"), _
DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, ConsecutiveDelimiter _
:=True, Tab:=False, Semicolon:=False, Comma:=False, Space:=True, _
Other:=False, FieldInfo:=Array(Array(1, 4), Array(2, 9)), _
TrailingMinusNumbers:=True
Selection.NumberFormat = "m/d/yyyy"
ActiveWindow.SmallScroll Down:=-45
Cells.Select
Dim dataname As String
Dim newsheet As String
dataname = ActiveSheet.ListObjects(1).Name
Sheets.Add
newsheet = ActiveSheet.Name
ActiveWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:= _
dataname, Version:=6).CreatePivotTable TableDestination:= _
newsheet & "!R3C1", TableName:="PivotTable10", DefaultVersion:=6
Sheets(newsheet).Select
Cells(3, 1).Select
With ActiveSheet.PivotTables("PivotTable10")
.ColumnGrand = True
.HasAutoFormat = True
.DisplayErrorString = False
.DisplayNullString = True
.EnableDrilldown = True
.ErrorString = ""
.MergeLabels = False
.NullString = ""
.PageFieldOrder = 2
.PageFieldWrapCount = 0
.PreserveFormatting = True
.RowGrand = True
.SaveData = True
.PrintTitles = False
.RepeatItemsOnEachPrintedPage = True
.TotalsAnnotation = False
.CompactRowIndent = 1
.InGridDropZones = False
.DisplayFieldCaptions = True
.DisplayMemberPropertyTooltips = False
.DisplayContextTooltips = True
.ShowDrillIndicators = True
.PrintDrillIndicators = False
.AllowMultipleFilters = False
.SortUsingCustomLists = True
.FieldListSortAscending = False
.ShowValuesRow = False
.CalculatedMembersInFilters = False
.RowAxisLayout xlCompactRow
End With
With ActiveSheet.PivotTables("PivotTable10").PivotCache
.RefreshOnFileOpen = False
.MissingItemsLimit = xlMissingItemsDefault
End With
ActiveSheet.PivotTables("PivotTable10").RepeatAllLabels xlRepeatLabels
With ActiveSheet.PivotTables("PivotTable10").PivotFields("Created")
.Orientation = xlRowField
.Position = 1
End With
ActiveSheet.PivotTables("PivotTable10").AddDataField ActiveSheet.PivotTables( _
"PivotTable10").PivotFields("Created"), "Count of Created", xlCount
Range("A3").Select
With ActiveSheet.PivotTables("PivotTable10").PivotFields("Date")
End With
Range("A2:B2").Select
With Selection
.HorizontalAlignment = xlCenter
.VerticalAlignment = xlBottom
.WrapText = False
.Orientation = 0
.AddIndent = False
.IndentLevel = 0
.ShrinkToFit = False
.ReadingOrder = xlContext
.MergeCells = False
End With
Selection.Merge
ActiveCell.FormulaR1C1 = "Microsoft Outlook "
Range("A3").Select
End Sub
我想运行一个宏,该宏创建数据透视表,将日期格式化为所需的格式,并显示每天的总计数。