Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/excel/28.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Excel 函数属性数据透视表类_Excel_Vba_Pivot Table - Fatal编程技术网

Excel 函数属性数据透视表类

Excel 函数属性数据透视表类,excel,vba,pivot-table,Excel,Vba,Pivot Table,我不知道围绕这个错误的问题是什么。我根据我所做的其他报告对这段代码进行了建模,其中没有错误。但是这个无法获取PivotFields类的Function属性。无论我使用xlSum还是XlCount,都会出现此错误 Function exportXl(strSD As String, strED As String) As String Dim fname As String, fso As Object, xlApp As Object, xlBook As Object, xlSheet

我不知道围绕这个错误的问题是什么。我根据我所做的其他报告对这段代码进行了建模,其中没有错误。但是这个无法获取PivotFields类的Function属性。无论我使用xlSum还是XlCount,都会出现此错误

    Function exportXl(strSD As String, strED As String) As String
Dim fname As String, fso As Object, xlApp As Object, xlBook As Object, xlSheet As Object, xlObj As Object, xlPT As Object, xlPC As Object, c As Object
fname = CurrentProject.Path & "\SupervisorEscalationsReport_" & Replace(strED, "/", "-") & ".xlsx"

Set fso = CreateObject("Scripting.FileSystemObject")
If fso.FileExists(fname) Then Kill fname

DoCmd.TransferSpreadsheet acExport, acSpreadsheetTypeExcel12Xml, "t_SiebCnt", fname

Set xlApp = CreateObject("Excel.Application")
xlApp.Visible = True
Set xlBook = xlApp.workbooks.Open(fname)
Set xlSheet = xlBook.sheets(1)

With xlSheet
    .Name = "t_SiebCnt"
    Set xlObj = .ListObjects.Add(1, .Range("$A$1:" & .Cells(1, 1).SpecialCells(11).Address), , 1)
    xlObj.Name = "Src_Table"
    xlObj.TableStyle = "TableStyleMedium16"
End With

Set xlPC = xlBook.PivotCaches.Create(1, "Src_Table", 5)
Set xlSheet = xlBook.sheets.Add
xlSheet.Name = "Report"

xlApp.ScreenUpdating = False

Set xlPT = xlPC.CreatePivotTable(xlSheet.Range("A3"), "Supervisor Escalation Rollup Report")

With xlPT

    With .PivotFields("AssignedToSalesID")
        .Orientation = xlPageField
        '.Position = 1
        .Caption = "Sales ID"
    End With

    With .PivotFields("Location")
        .Orientation = xlRowField
        '.Position = 1
        .Caption = "Site"
    End With

     With .PivotFields("FullName")
        .Orientation = xlRowField
        '.Position = 1
        .Caption = "Supervisor Name"
    End With

      With .PivotFields("Generated_On")
        .Orientation = xlRowField
       ' .Position = 2
        .Caption = "Day Generated"
    End With

      With .PivotFields("Closed_On")
        .Orientation = xlRowField
       ' .Position = 2
        .Caption = "Day Closed"
    End With

    With .PivotFields("DaysOpen")
        .Orientation = xlRowField
       ' .Position = 2
        .Caption = "Days Open"
    End With

   With .PivotFields("Status")
        .Orientation = xlRowField
       ' .Position = 2
        .Caption = "Status"
    End With




   With .PivotFields("CountActivityUID")
        .Orientation = xlDataField
        .Function = xlCount
        .NumberFormat = "#,##0"
        .Caption = "Count of Status"
    End With


.PivotFields("Day Generated").ShowDetail = False



    .TableStyle2 = "PivotStyleMedium2"
    .RowAxisLayout 1
    .InGridDropZones = True
    .DisplayErrorString = True
End With


上面是完整的代码以及我创建透视表的表的示例图像

我假设这不是问题所在,但您是否正在处理OLAP数据?见。不@BigBen我不是。它只是来自Hadoop中的一个数据库,您可以手动创建该字段?是的,我可以毫无问题地手动创建它。您是否可以提供一个数据示例,以提供足够的代码进行复制?显示布局的图像。减少到足以重新处理问题的程度。