2016-02-12 102 views
0

我期望這是一個簡單的問題,但我找不到一個可行的解決方案。我在一個簡單的電子表格上有四個按鈕,我想與列的邊緣水平對齊,並在它們之間獲得一致的空間。我在開發人員設計模式中使用了「格式控制」選項,使它們全部保持一致的長度和寬度。我現在的問題是在工作表上放置。他們處於沒有機會增加影響他們的行或列的位置。我會很感激任何幫助。 Thankss。如何設置Excel電子表格中按鈕的位置?

回答

0

希望這可以幫助你。

Sub setPosition() 
    ActiveSheet.Shapes.Range(Array("CommandButton1", "CommandButton2", "CommandButton3", "CommandButton4")).Select 

    With Selection 
     .Width = 150 
     .Height = 30 
     .Left = Range("C2").Left 'here you can take the cell of the column 
           'you want to set as a hedge 
    End With 

    'Set the top of the buttons with the property "top" of a cell 
    Me.CommandButton1.Top = Range("C2").Top 
    Me.CommandButton2.Top = Range("C5").Top 
    Me.CommandButton3.Top = Range("C8").Top 
    Me.CommandButton4.Top = Range("C11").Top 

    'optional 
    'With this code you can aling and distribute all the shapes (buttons) 
    Selection.ShapeRange.Distribute msoDistributeVertically, msoFalse 
    Selection.ShapeRange.Distribute msoDistributeHorizontally, msoFalse 
    Selection.ShapeRange.Align msoAlignCenters, msoFalse 
    Selection.ShapeRange.Align msoAlignLefts, msoFalse 
End Sub 

如果您需要更多信息,請告訴我。