在Excel / VBA中禁用/启用按钮 [英] Disable/Enable button in Excel/VBA

查看:1253
本文介绍了在Excel / VBA中禁用/启用按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在VBA / Excel中尝试以下功能:

I'm trying the following function in VBA/Excel:

Sub function_name()
  button.enabled=false
  Call Long_Function       ' duration: 10sec
  button.enabled=true
End Sub

由于某些原因,此按钮禁用不起作用(在excel工作表中保持启用)
我尝试尝试使用DoEvents和延迟,但没有运气。
任何想法?
谢谢!

For some reason, this button disabling does not work (it stays enabled in the excel work sheet) I tried experimenting with DoEvents and delays, but no luck there. Any ideas? Thanks!

推荐答案

以下内容适用于我(Excel 2010)

The following works for me (Excel 2010)

Dim b1 As Button

Set b1 = ActiveSheet.Buttons("Button 1")

b1.Font.ColorIndex = 15
b1.Enabled = False
Application.Cursor = xlWait
Call aLongAction
b1.Enabled = True
b1.Font.ColorIndex = 1
Application.Cursor = xlDefault




注意 .enabled = False 不灰色按钮。

字体颜色必须明确设置,以使其变灰。

The font color has to be set explicitely to get it grayed.

这篇关于在Excel / VBA中禁用/启用按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆