VBA Application.Caller 运行时错误

标签 vba excel runtime-error

我在 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 时。 我将复选框分配给子 Kontrollkästchen_KlickenSieAuf() 如果有人能帮助我,我会很高兴。

问候

最佳答案

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

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

例如。

关于VBA Application.Caller 运行时错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24649061/

相关文章:

c# - 如何转义公式中的双引号

excel - 粘贴数组时的VBA,NumberFormat

Excel:导出一个带有所有宏的功能区选项卡

excel - 跨工作表排除范围

c++ - 指针访问冲突? - C++

matlab - 计算 eigs 时出现神秘的 matlab 错误

Android:NoSuchFieldError 指的是 appcompat_v7 缺少 R$styleable.Theme_windowActionBar

excel - 如何在文本框中允许仅 double 据类型?

excel - 无法从 Excel 中完全删除 xlwings 插件

Excel VBA 用于更改雷达图上的标记大小、颜色和透明度