Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Command Button alignment

Status
Not open for further replies.
May 14, 2004
108
US
Is there a way to "snap" a row or column of command buttons to align the tops or lefts on a worksheet? Even have the ability to get in and modify the left and top properties would work, if possible.
 
The following procedure should get you started. It aligns every CommandButton on the active worksheet with the top & left edge of the cell it is currently postioned over. To test, create a CommandButton (using the Control Toolbox toolbar) on a worksheet then hold down the Ctrl key while clicking and dragging with the mouse to quickly create several additonal buttons. Move these around to different cells or even in different rows of the same column. Run the procedure.
Code:
Sub AlignButtons()
Dim oBtn As OLEObject

   With ActiveSheet
     For Each oBtn In .OLEObjects
       If InStr(1, oBtn.Name, "CommandButton", vbTextCompare) > 0 Then
         oBtn.Top = oBtn.TopLeftCell.Top
         oBtn.Left = oBtn.TopLeftCell.Left
       End If
     Next oBtn
   End With
 
End Sub

Regards,
Mike
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top