有没有办法在Form Control按钮上编辑标题? [英] Is there a way to edit caption on Form Control buttons?

查看:139
本文介绍了有没有办法在Form Control按钮上编辑标题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以(在表单更改事件中)更改表单控件按钮的标题文本?



理想情况下,我想添加一个变量现有的按钮标题取决于工作簿中的其他数据。

解决方案

好的,右键单击电子表格底部的Sheet1选项卡,选择查看代码



复制粘贴以下代码

  Private Sub Worksheet_Activate ()
按钮(Button 1)Caption =NEW TEXT
End Sub

当Sheet1被激活并且将按钮上的标题更改为 NEW TEXT



显然你可以通过名称或索引来引用你的按钮。如果要修改不同对象的文本,您将修改Button 1



您如果您替换NEW TEXT



,可以为其指定变量或表达式的评估。例如

如果在 Sheet2 ,您可以在单元格A1中输入任何内容,您可以修改Sheet1后面的代码,并使用

  Private Sub Worksheet_Activate()
按钮(Button 1)Caption = Sheets(Sheet2)。Range(A1 )
End Sub

这种方式每次激活Sheet1时,按钮上的文本将从Sheet1,单元格A1中获取



要查找按钮的名称,请看这里




Is it possible (on a sheet change event), to change the caption text of a Form Control button?

Ideally, I would like to add a variable into the existing button caption depending on other data in the workbook.

解决方案

Well, right click the Sheet1 tab on the bottom of spreadsheet and select view code

Copy paste the following code

Private Sub Worksheet_Activate()
    Buttons("Button 1").Caption = "NEW TEXT"
End Sub

This event fires up when Sheet1 gets activated and it changes the caption on the button to NEW TEXT

Obviously you can refer to your buttons either by name or their index. You would to modify the "Button 1" if you want to modify the text on a different object.

You can assign it a variable or evaluation of an expression if you replace the "NEW TEXT"

For example

if on Sheet2 you type anything in the cell A1 you can modify the code behind Sheet1 and use

Private Sub Worksheet_Activate()
    Buttons("Button 1").Caption = Sheets("Sheet2").Range("A1")
End Sub

this way every time you activate Sheet1 the text on a button will be picked up from Sheet1, Cell A1

To find out the name of the button look here

这篇关于有没有办法在Form Control按钮上编辑标题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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