2016-02-12 101 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 

如果您需要更多信息,请告诉我。