Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/vba/15.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
Vba 宏用作按钮,但不用作UI功能区_Vba_Excel - Fatal编程技术网

Vba 宏用作按钮,但不用作UI功能区

Vba 宏用作按钮,但不用作UI功能区,vba,excel,Vba,Excel,我在Excel中编写了一个非常简单的VBA宏,用于在列1中只有一个字母时突出显示行。当从窗体控件按钮运行时,代码可以正常工作,但不能从功能区中的自定义UI按钮运行(当然,使用eventhandler)。代码如下: Dim counter As Integer Dim index As String counter = 1 While Not index = "" On Error Resume Next index = ActiveWorkbook.ActiveSheet.C

我在Excel中编写了一个非常简单的VBA宏,用于在列1中只有一个字母时突出显示行。当从窗体控件按钮运行时,代码可以正常工作,但不能从功能区中的自定义UI按钮运行(当然,使用eventhandler)。代码如下:

Dim counter As Integer
Dim index As String

counter = 1

While Not index = ""
    On Error Resume Next
    index = ActiveWorkbook.ActiveSheet.Cells(counter, 1).Value

    If Len(index) = 1 Then
        ActiveSheet.Rows(counter).Interior.ColorIndex = 16
    End If

    counter = counter + 1
Wend

你知道为什么吗?我假设这与找不到ActiveWorkBook有关。

您是否尝试将其(代码)放入模块中?我将其放入此工作簿中,它与我的所有其他自定义UI按钮一起工作正常。我使用onAction=“ThisWorkbook.highlight\u eventhandler”调用它在customUI编辑器@mukul215中,我看不出代码应该出现在此工作簿中的任何原因。将其移动到标准模块,看看是否有效。@DickKusleika谢谢。那确实有效。不知道为什么。这本工作手册以前一直对我有用