【问题标题】:VBA Application.Caller runtime errorVBA Application.Caller 运行时错误
【发布时间】:2014-08-30 04:56:59
【问题描述】:

我在 VBA 中有以下代码:

Sub Kontrollkästchen_KlickenSieAuf()
With ThisWorkbook.Sheets("Hinterlegungsmatrix Auswahl")
Dim i, j, rowx, columnx As Integer
rowx = Application.Caller.row 'I got here the run time error (object required)-->.row doesn't work
columnx = Application.Caller.column 'I got here the run time error (object required)-->.column doesn't work
        If Worksheets("Hinterlegungsmatrix Auswahl").Cells(rowx, columnx).Value = True Then
              For i = 6 To 22
                For j = 3 To 22
                    If (Worksheets("Hinterlegungsmatrix Auswahl").Cells(i, j).Interior.Color = RGB(250, 192, 144)) Or (Worksheets("Hinterlegungsmatrix Auswahl").Cells(i, j).Interior.Color = RGB(83, 142, 213)) Or (Worksheets("Hinterlegungsmatrix Auswahl").Cells(i, j).Interior.Color = RGB(242, 221, 220)) Then
                      Worksheets("Hinterlegungsmatrix Auswahl").Cells(i, j).Value = True
                    End If
                Next j
            Next i
        End If
End With
End Sub

我想获取激活复选框的单元格,但它会引发运行时错误,我使用 Application.Caller.Address 或 .Row 或 .Column。 我为复选框分配了 sub Kontrollkästchen_KlickenSieAuf() 如果有人可以帮助我,我会很高兴。

问候

【问题讨论】:

  • 也许您可以告诉我们您要做什么,因为Application.Caller 仅适用于 UDF,而您似乎正试图从 Sub 过程中调用它
  • 您好,谢谢您的回答。我想找到单击复选框的单元格,这意味着行和列。问题是我有大约 30 个复选框,我只会为所有这些复选框写 1 个子,这意味着将复选框分配给子。
  • 你是指复选框where所在的单元格,还是当前活动的单元格when复选框被点击?
  • 复选框所在的位置,因为如果活动单元格与单击的复选框不同,则活动单元格可能不起作用。
  • 我们在这里讨论什么样的复选框? ActiveX 还是表单?

标签: vba excel runtime-error


【解决方案1】:

Application.Caller 是一个字符串(控件的名称)而不是一个对象,并且复选框没有行属性。你需要使用:

ActiveSheet.Shapes(Application.Caller).TopLeftCell.Row

例如。

【讨论】:

  • Application.Caller 并不总是一个字符串。这取决于调用者的类型...
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2018-12-23
  • 2016-03-25
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多