以编程方式将带有宏的按钮添加到Excel文件 [英] Programmatically add a button with a macro to an Excel file

查看:51
本文介绍了以编程方式将带有宏的按钮添加到Excel文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Excel VBA应用程序创建格式化的工作表,并且我想在创建时以编程方式向每个工作表添加一个按钮.此按钮必须附加一个宏,该宏在特殊单元格中显示某个范围内某个值的平均值,并根据平均值来更改此单元格的背景色.这可能吗,如果可以,我该怎么办?

I'm creating formated worksheets with an Excel VBA application and I would like to add programmatically add a button to each worksheet when created. This button must have a macro attached to it, which display the average of the values in a certain range in a special cell, and change the background color of this cell depending on the value of the average. Is it possible to this, and if yes, how can I do it ?

推荐答案

您可以像这样或示例添加按钮:

You can add the Button like this or example:

ActiveSheet.Buttons.Add(52.5, 7.5, 173.25, 41.25).Select 'Arguments are coordinates
Selection.OnAction = "Button_Click"

现在,确保Button_Click子项具有您想要的逻辑.

Now make sure the Button_Click sub has the logic you want.

这篇关于以编程方式将带有宏的按钮添加到Excel文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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