Macro to Add CommandButton & Assign Macro Code

  • I written VBA code to create a new sheet and embed a command button on it. I want to assign a macro to this button but when I click on the button the assign macro button is greyed out. I have plenty of macros saved and the VBA code has finished running so why should this be?:confused:

  • Re: Command buttons


    As requested:

  • Re: Command buttons


    Hi,


    There seems to be something in the background that enables the attachment of macro codes. I have the same problem with ComboBoxes that don't have the tab to assign cells as data sources etc.


    I'd get one that works and duplicate it on your new sheet or add the macro to a menu or as noted above.


    John

  • Re: Command buttons


    I would just stick to putting a simple button on your sheet and not going down the OLEObjects route. To tidy up my code a bit.


    Code
    Sub sf()
    Dim butTemp
    Set butTemp = ActiveSheet.Buttons.Add(298.5, 114, 72, 72)
    With butTemp
        .OnAction = "'Accounts Tools.xls'!addmissing"
        .Caption = "Press ME"
    End With
    Set butTemp = Nothing
    End Sub
  • Re: Command buttons


    guyfos, please pay close attention to our rules on Thread Titles. You current one (I will change) is of no use at all as it's too broad. Why not something like Macro to Add CommandButton & Assign Macro Code as that is your problem.


    Anymore violations will result in your post being deleted.

Participate now!

Don’t have an account yet? Register yourself now and be a part of our community!