Change button type, caption and assign macro

cgcamal

Active Member
Joined
May 2, 2007
Messages
472
Hi everyone,

I have several "shapes" buttons (ActiveX control) in Sheet1 and I'm trying to replace each one of those buttons with
"normal" buttons (Userform control) using the same position (height, width, left, top), same Caption text of the existing
buttons, and assign all new buttons to the same "Macro1".

I'm trying with:
Code:
Sub Change_Buttons_Type()
Dim Shps As Shape, sh As Integer

For Each Shps In ActiveSheet.Shapes
    sh = sh + 1

    With Shps
        If .OLEFormat.Object.Name Like "CommandButton*" Then
            ActiveSheet.Buttons.Add(.Left, .Top, .Width, .Height).OnAction = "Macro1"
            ActiveSheet.Shapes.Range(Array([B][COLOR=Red]CurrentButton[/COLOR][COLOR=Red]Added[/COLOR][/B])).Characters.Text = [COLOR=Red][B].Caption
            [/B][/COLOR]ActiveSheet.Shapes.Range(Array(.OLEFormat.Object.Name)).Delete
        End If
    End With
Next
End Sub
Because my code is not finished, I think is correct except parts in red. I don't know how to say that the current
control created take the caption of the current shape that will be deleted.

I hope someone could help me with this.

Thanks in advance.

Regards
 
Last edited:

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Cesar

I don't quite follow.

You have some ActiveX 'shapes buttons' which you want to replace with 'userform' command buttons.

How exactly did you create the original 'buttons'?

As far as I know there isn't an ActiveX 'shape' object, not in the default toolbox.

Also, aren't 'userform' buttons ActiveX?
 
Upvote 0
Try:

Code:
Sub Change_Buttons_Type()
    Dim Cmd As OLEObject
    Dim Btn As Button
    For Each Cmd In ActiveSheet.OLEObjects
        With Cmd
            If TypeName(.Object) = "CommandButton" Then
                Set Btn = ActiveSheet.Buttons.Add(.Left, .Top, .Width, .Height)
                With Btn
                    .OnAction = "Macro1"
                    .Caption = Cmd.Object.Caption
                End With
                Cmd.Delete
            End If
        End With
    Next Cmd
End Sub
 
Upvote 0

Forum statistics

Threads
1,224,616
Messages
6,179,911
Members
452,949
Latest member
beartooth91

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top