Excel VBA 更改按钮大小和位置

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/7959253/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 12:08:07  来源:igfitidea点击:

Excel VBA change button size and location

excelvbalocationsize

提问by Steven

How do I change a button size and location on an excel sheet?

如何更改 Excel 工作表上的按钮大小和位置?

回答by chris neilsen

You are almost there with ActiveSheet.Shapes("Button 1")

你快到了 ActiveSheet.Shapes("Button 1")

If you dima variable as Shapeand assign the button to it, you can use intellisence to explore the available properties. From there you will find .Height, .Width, .Left, .Top

如果您dim将变量设为Shape并为其分配按钮,则可以使用智能来探索可用的属性。从那里你会发现.Height, .Width, .Left,.Top

Dim btn As Shape
Set btn = ActiveSheet.Shapes("Button 1")
btn.Height = 50
btn.Width = 100

回答by PowerUser

Steven, to learn basic VBA in Excel, I recommend experimenting with the Record Macrooption. It's location varies depending on your version of Excel (In 2007, you need to activate the Developer tab in your ribbon).

Steven,要在 Excel 中学习基本的 VBA,我建议您尝试使用Record Macro选项。它的位置因您的 Excel 版本而异(在 2007 中,您需要激活功能区中的“开发人员”选项卡)。

With this button turned on, use the standard menus to do whatever you wanted to do in the first place (in this case, make a custom sized button). Then stop the recording and look at the auto-generated code you just made.

打开此按钮后,首先使用标准菜单执行您想做的任何事情(在这种情况下,制作自定义大小的按钮)。然后停止录制并查看您刚刚制作的自动生成的代码。