【问题标题】:Referencing ThisWorkbook produces Run Time Error 429引用 ThisWorkbook 会产生运行时错误 429
【发布时间】:2020-04-11 05:37:34
【问题描述】:

下面的代码抛出

运行时错误 429 activex 组件无法创建对象

With ThisWorkbook.

    Dim myFirstRow As Long 
    Dim myLastRow As Long 
    Dim myFirstColumn As Long 
    Dim myLastColumn As Long 
    Dim mySourceData As String 
    Dim myDestinationRange As String 
    Dim mySourceWorksheet As Worksheet 
    Dim myDestinationWorksheet As Worksheet 
    Dim myPivotTable As PivotTable

    With ThisWorkbook    ' ** 
       Set mySourceWorksheet = .Worksheets("WAM_RAW_DATA")
       Set myDestinationWorksheet = .Worksheets.Add 
    End With 

    myDestinationRange = myDestinationWorksheet.Range("A5").Address(ReferenceStyle:=xlR1C1)
    myFirstRow = 1
    myLastRow = 2020
    myFirstColumn = 1
    myLastColumn = 40

    With mySourceWorksheet.Cells
        mySourceData = .Range(.Cells(myFirstRow, myFirstColumn), .Cells(myLastRow, myLastColumn)).Address(ReferenceStyle:=xlR1C1) 
    End With 

    Set myPivotTable = ThisWorkbook.PivotCaches.Create(SourceType:=xlDatabase, SourceData:=mySourceWorksheet.Name & "!" & mySourceData).CreatePivotTable(TableDestination:=myDestinationWorksheet.Name & "!" & myDestinationRange, TableName:="PivotTableNewSheet")

    With myPivotTable 
        .PivotFields("Agent Name").Orientation = xlRowField 
        .Position = 1 
    End With

    With myPivotTable 
        .PivotFields("Login Date").Orientation = xlColumnField 
        .Position = 1 
    End With

    With myPivotTable 
        .PivotFields("Login Time").Orientation = xlDataField 
        .Position = 1 
        .Function = xlMin 
        .NumberFormat = "h:mm:ss" 
    End With
End Sub

【问题讨论】:

  • 请告诉您在哪一行得到错误。不可能发生在这里With ThisWorkbook
  • 它在第 10 行,当我运行一个宏时它卡住了,这个工作簿行以黄色突出显示
  • 您是在一个活动的 excel 应用程序中运行它吗?
  • 是的,我在一个活动的 Excel 工作表中运行它

标签: excel vba runtime-error


【解决方案1】:

这可能有助于How do I resolve "Run-time error '429': ActiveX component can't create object"?

不过,与此同时,您可以尝试其他一些解决方案来使用该语句,例如:

Dim WB As Workbook

Set WB = ActiveWorkbook
    ! OR !
Set WB = Workbooks("name of workbook.xlsm")

【讨论】:

  • 第二个...谢谢
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多