Is it possible, Using VBA to size and position Button controls that are on a worksheet. I am not referring to a VBA form with a button.
Is it possible, Using VBA to size and position Button controls that are on a worksheet. I am not referring to a VBA form with a button.
Hello excelbobabc,
Yes, you can. Each button control has a set of properties that determines its size and position. These properties apply to both Forms and Control Toolbox buttons.
Button Size Properties
1. Height
2. Width
Button Position Properties
These are relative references from the upper left corner of Screen.
1. Left
2. Top
Sincerely,
Leith Ross
Remember To Do the Following....
1. Use code tags. Place [CODE] before the first line of code and [/CODE] after the last line of code.2. Thank those who have helped you by clicking the Star below the post.3. Please mark your post [SOLVED] if it has been answered satisfactorily.
Old Scottish Proverb...
Luathaid gu deanamh maille! (Rushing causes delays!)
Can you show me how to access these properties from VBA? I am not sure how to reference the controls on a sheet.
Thanks
Hello excelbobabc,
There are several ways to do this. Since I don't know which approach will work best for you, I will start with the most basic. This involves knowing the name of the button. Not the caption, the part the user sees, but the object name that appears in the Name Box. The box to the left of the Formula Bar.
Default Control Names
The each button type, Forms and Control ToolBox, have a default naming convention. The Forms button will be named like "Button 1". The number one will change depending on the number of controls and other graphics that have been added already. These numbers are sequential.
The Control ToolBox buttons are named like "CommandButton1". The number for thiese controls is also sequential, but only for that type of control. You could have 5 buttons on the worksheet and then add an OptionButton. If it is the first type of this control it will be OptionButton1.
Moving a Control using a Cell as a Reference
Once you know the control's name, it can be easily moved elsewhere on the worksheet. The easiest method is to use a cell as our reference point. The sheet the control is on must the active. This will place the upper left corner of the button in upper left corner of cell "D5".
Example for a Forms Button
Example for a Control ToolBox Command ButtonPlease Login or Register to view this content.
Please Login or Register to view this content.
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks