Share via

Command Button Moves After Startup

Anonymous
2012-06-07T15:32:03+00:00

I created 3 command buttons in Excel 2010 and positioned the button exactly where I like it.   The problem I have is every time I close and reopen the file, the buttons moves to the left and I end up repositioning it.  Is there a way I can lock the button location in one location on the spreadsheet?

Thank you for your help!

Microsoft 365 and Office | Excel | For home | Windows

Locked Question. This question was migrated from the Microsoft Support Community. You can vote on whether it's helpful, but you can't add comments or replies or follow the question.

0 comments No comments

Answer accepted by question author

Anonymous
2012-06-07T16:38:01+00:00

Sure  this takes advantage of the fact the Buttons are a subset of Shapes:

Sub dural()

ActiveSheet.Shapes("Button 1").Left = Range("D9").Left

ActiveSheet.Shapes("Button 1").Top = Range("D9").Top

End Sub

Put code like this in a worksheet activate event macro:

Private Sub Worksheet_Activate()

ActiveSheet.Shapes("Button 1").Left = Range("D9").Left

ActiveSheet.Shapes("Button 1").Top = Range("D9").Top

End Sub

Because it is worksheet code, it is very easy to install and automatic to use:

   1. right-click the tab name near the bottom of the Excel window

   2. select View Code - this brings up a VBE window

   3. paste the stuff in and close the VBE window

If you have any concerns, first try it on a trial worksheet.

If you save the workbook, the macro will be saved with it.

To remove the macro:

   1. bring up the VBE windows as above

   2. clear the code out

   3. close the VBE window

To learn more about macros in general, see:

http://www.mvps.org/dmcritchie/excel/getstarted.htm

To learn more about Event Macros (worksheet code), see:

http://www.mvps.org/dmcritchie/excel/event.htm

Was this answer helpful?

0 comments No comments

3 additional answers

Sort by: Most helpful
  1. Anonymous
    2012-06-07T17:01:07+00:00

    Thank you so much for your help!  :-)

    Was this answer helpful?

    0 comments No comments
  2. Anonymous
    2012-06-07T16:11:12+00:00

    I'm pretty sure I understand what you said, but do you mind writing an example for me how to write and spell out the code?

    Was this answer helpful?

    0 comments No comments
  3. Anonymous
    2012-06-07T16:07:11+00:00

    Rather than "locking", consider using either a Workbook Open or Worksheet Activate event macro to position the buttons relative to some cell boundaries.  Even if the button have not moved, no harm is done.

    Was this answer helpful?

    0 comments No comments