如何在Excel VBA中将单击的按钮背景色格式化为黄色?

如何在Excel VBA中将单击的按钮背景色格式化为黄色?,excel,vba,button,Excel,Vba,Button,如果单元格的值不是空的或“”,则尝试将非ActiveX按钮的背景更改为黄色 投掷 错误424需要对象 我不确定你正在尝试的东西是否能像你尝试的那样完成。我会这样做: Sub Button37_Click() If Not ActiveSheet.Range("I16") Is Nothing Then 'I used the macro recorder here, just so that you can too. just copy paste what it

如果单元格的值不是空的或“”,则尝试将非ActiveX按钮的背景更改为黄色

投掷

错误424需要对象


我不确定你正在尝试的东西是否能像你尝试的那样完成。我会这样做:

Sub Button37_Click()

      If Not ActiveSheet.Range("I16") Is Nothing Then

        'I used the macro recorder here, just so that you can too. just copy paste what it gives you.
        With ActiveSheet.Shapes.Range(Array("Rectangle 1")).ShapeRange.Fill
            .Visible = msoTrue
            .ForeColor.ObjectThemeColor = msoThemeColorAccent4
            .ForeColor.TintAndShade = 0
            .ForeColor.Brightness = 0.400000006
            .Transparency = 0
            .Solid
        End With

    End If
      Range("GuarantorDetails").Copy
End Sub
信息:我不认为你可以改变一个普通按钮的颜色,而是使用一个形状

我认为如果在工作表的单元格上使用IsEmpty(),则不会给出一致的(如果有)结果

命名区域的名称中有一个空格。至少对于我的excel版本,这是不允许的


我创建了一个矩形并将其重命名为“Button 37”

您的
范围(“GuarantorDetails”)中缺少目标。复制
如果您使用表单控件按钮,则无法更改背景颜色。@BigBen这是一个非activex表单控件按钮,位于一张工作表上,可将一个范围复制到剪贴板以从外部粘贴。效果非常好。是的,我现在意识到非活动的x按钮不能改变它的背面颜色!再次感谢你
Sub Button37_Click()

      If Not ActiveSheet.Range("I16") Is Nothing Then

        'I used the macro recorder here, just so that you can too. just copy paste what it gives you.
        With ActiveSheet.Shapes.Range(Array("Rectangle 1")).ShapeRange.Fill
            .Visible = msoTrue
            .ForeColor.ObjectThemeColor = msoThemeColorAccent4
            .ForeColor.TintAndShade = 0
            .ForeColor.Brightness = 0.400000006
            .Transparency = 0
            .Solid
        End With

    End If
      Range("GuarantorDetails").Copy
End Sub