+ Reply to Thread
Results 1 to 4 of 4

Change size and position of Buttons on Excel sheet?

  1. #1
    Registered User
    Join Date
    10-02-2008
    Location
    Michigan
    Posts
    68

    Change size and position of Buttons on Excel sheet?

    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.

  2. #2
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Change size and position of Buttons on Excel sheet?

    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!)

  3. #3
    Registered User
    Join Date
    10-02-2008
    Location
    Michigan
    Posts
    68

    Re: Change size and position of Buttons on Excel sheet?

    Can you show me how to access these properties from VBA? I am not sure how to reference the controls on a sheet.

    Thanks

  4. #4
    Forum Moderator Leith Ross's Avatar
    Join Date
    01-15-2005
    Location
    San Francisco, Ca
    MS-Off Ver
    2000, 2003, & 2010
    Posts
    23,258

    Re: Change size and position of Buttons on Excel sheet?

    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
    Please Login or Register  to view this content.
    Example for a Control ToolBox Command Button
    Please Login or Register  to view this content.

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1