VBA - 如何更改按钮文本
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/42000204/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
VBA - How to change the button text
提问by Belgacem Ksiksi
I assigned an Excel VBA macro to a command button, and I am needing to know how to update the text to "Loading" when the macro is executed.
我为命令按钮分配了一个 Excel VBA 宏,我需要知道如何在执行宏时将文本更新为“正在加载”。
I have tested the following code with no success:
我已经测试了以下代码但没有成功:
Worksheets("Sheet1").Button9.Caption = "Loading"
回答by Alex K.
Go via the Buttonscollection:
通过Buttons集合:
Worksheets("Sheet1").Buttons("Button9").Text = "Loading"
回答by Anand
You should try using an Active X button and add this code to that active X button click event. Also, put this code in the same worksheet where this active X button is.:
您应该尝试使用 Active X 按钮并将此代码添加到该活动 X 按钮单击事件。此外,将此代码放在此活动 X 按钮所在的同一工作表中。:
I am assuming your button starting text is "Original Text". You can replace it with your own text in the code. Also, I am adding 5 seconds delay just to mimic that something is loading. you can replace that part with your code. Also note that in my case active X button name is CommandButton21, in your case it may be different. Update your code accordingly.
我假设您的按钮起始文本是“原始文本”。您可以在代码中用您自己的文本替换它。另外,我添加了 5 秒延迟只是为了模仿正在加载的东西。您可以用您的代码替换该部分。另请注意,在我的情况下,活动 X 按钮名称是 CommandButton21,在您的情况下,它可能会有所不同。相应地更新您的代码。
Private Sub CommandButton21_Click()
CommandButton21.Caption = "Loading"
Application.Wait (Now + TimeValue("0:00:05"))
CommandButton21.Caption = "Original Text"
End Sub
回答by Excelgzh
This worked for me
这对我有用
Worksheets("Sheet1").Button9.TextFrame.Characters.Text = "Loading"
Worksheets("Sheet1").Button9.TextFrame.Characters.Text = "Loading"

