Results 1 to 3 of 3
  1. #1
    New Lounger
    Join Date
    Jan 2003
    Location
    Colorado Springs, Colorado, USA
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Mass rename of macro buttons (2000 SP1a)

    I've got a user who has a couple of workbooks that have about 100 sheets each. He created a button on each sheet that runs a macro. Unfortunately, he wants to rename the button on all of the sheets. As far I know, Excel cannot find the button name on the find replace. Does anyone have any ideas on how to rename the buttons? I think he may have to manually rename each button.

  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: Mass rename of macro buttons (2000 SP1a)

    Command buttons are part of the Shapes collection of a worksheet. If there is just one per worksheet, it will be named "Button 1" if it was created from the Forms toolbar (seems most probable from your description) or "CommandButton1" if it was created from the Control Toolbox toolbar.

    This macro will rename buttons named "Button 1" to "cmdMacro". Adapt as needed.

    Sub RenameButtons()
    Dim sht As Worksheet
    On Error GoTo ErrHandler
    For Each sht In ActiveWorkbook.Worksheets
    sht.Shapes("Button 1").Name = "cmdMacro"
    Next sht

    ExitHandler:
    Set sht = Nothing
    Exit Sub

    ErrHandler:
    ' No error if button of that name is not found.
    If Err = -2147024809 Then
    Resume Next
    Else
    MsgBox Err.Description, vbExclamation
    Resume ExitHandler
    End If
    End Sub

  3. #3
    New Lounger
    Join Date
    Jan 2003
    Location
    Colorado Springs, Colorado, USA
    Posts
    22
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: Mass rename of macro buttons (2000 SP1a)

    Thanks! I'll have him run this macro on a copy of his workbook.

Posting Permissions

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