Excel 运行时错误';1004';无法获取数据透视表类的PivotFields属性

Excel 运行时错误';1004';无法获取数据透视表类的PivotFields属性,excel,vba,Excel,Vba,我开发了一个宏,它可以自动生成报告,但对于某些类型的数据,我收到了错误。我尝试了几件事,但都没能解决,所以我请求一些帮助,这是有问题的一行:Fin=.PivotTables(1).数据透视字段(“帐户所有者”).VisibleItems.Count,这是完整的代码: Sub Generar_informes() Dim i As Double Dim Ini As Double Dim Fin As Double 'Desactivamos actualización de pantalla

我开发了一个宏,它可以自动生成报告,但对于某些类型的数据,我收到了错误。我尝试了几件事,但都没能解决,所以我请求一些帮助,这是有问题的一行:
Fin=.PivotTables(1).数据透视字段(“帐户所有者”).VisibleItems.Count
,这是完整的代码:

Sub Generar_informes()

Dim i As Double
Dim Ini As Double
Dim Fin As Double

'Desactivamos actualización de pantalla
Application.ScreenUpdating = False
Sheets("Pivot Table").Select
With Sheets("Pivot Table")

'indicamos la fila siguiente a la primera fila con datos
Ini = Columns(1).Range("A1").End(xlDown).Row
'Contamos los todas los comerciales de la tabla dinámica1
Fin = .PivotTables(1).PivotFields("Account Owner").VisibleItems.Count

'Inciamos un bucle donde por cada comercial generamos informe
For i = 1 To Fin
'para mostrar el informe debemos hacer referencia a los campos de valores
.Cells(i + Ini, 2).ShowDetail = True
'Nombramos la pestaña con el nombre del comercial.
ActiveSheet.Name = .Cells(i + Ini, 1).Value
'Seleccionamos la hoja con el detalle del comercial
ActiveSheet.Select
'Movemos la hoja a un libro nuevo
ActiveSheet.Move
'Cambiamos color de celdas a modificar por los comerciales
Range("L1:N1").Interior.Color = RGB(255, 153, 0)
'Agregamos la lista desplegable
    Columns("N:N").Select
    With Selection.Validation
        .Delete
        .Add Type:=xlValidateList, AlertStyle:=xlValidAlertStop, Operator:= _
        xlBetween, Formula1:="Director,Manager,Owner,Staff,Top Executive(Chairman-Chief-etc),Vice President/SVP/EVP"
        .IgnoreBlank = True
        .InCellDropdown = True
        .InputTitle = ""
        .ErrorTitle = ""
        .InputMessage = ""
        .ErrorMessage = ""
        .ShowInput = True
        .ShowError = True
    End With



ActiveWorkbook.SaveAs Filename:=ThisWorkbook.Path & "\" & ActiveSheet.Name

ActiveWorkbook.Close False
Next i
End With
Application.ScreenUpdating = True
MsgBox "¡Reportes generados exitosamente!"
End Sub

高级版谢谢您。您遇到了什么错误?运行时错误“1004”无法获取数据透视表类的PivotFields属性,这意味着您所引用的数据透视表没有该名称的字段。但问题是它有:我命名了数据透视列。帐户所有者,这就是我在代码中提到的您是否有多个透视表?如果是这样,
。数据透视表(1)
可能引用了错误的表。