【发布时间】:2016-06-22 20:41:45
【问题描述】:
我正在寻找 Excel VBA 来动态更改 Excel 命令按钮上的标题。默认标题应为“显示差异”,并应在应用过滤器时更改为全部显示。
这是我目前所拥有的。
Sub ShowDifference()
Dim cmdButton As CommandButton
'在这里休息
Set cmdButton = ActiveSheet.Shapes("cmdShowDif")
If cmdButton.Caption = "Show Difference" Then
ActiveSheet.ListObjects("qryDifference").Range.AutoFilter Field:=4, _
Criteria1:=Array("<>0.00"), Operator:=xlAnd
cmdButton.Caption = "Show All"
Else
ActiveSheet.ListObjects("qryDifference").Range.AutoFilter Field:=4
cmdButton.Caption = "Show Difference"
End If
End Sub
它打破了潜艇的名称。为什么?
【问题讨论】:
-
错误是什么?
-
它破坏了 sub 的名称 - 您是否先编译了代码?标题和这个问题到底有什么关系?
-
抱歉忘记改标题了。错误信息见附图。
-
您使用的是表单控件还是 ActiveX 控件?顺便说一句,错误是因为没有
CommandButton这样的东西(声明变量时)。 -
我正在使用默认的 Excel 命令按钮,我在其他地方找到了代码并对其进行了修改。在应用过滤器以及删除过滤器时,我正在尝试更改按钮上的标题。