VBA code to create macro, insert form control button, assign macro to button

Harksey

New Member
Joined
May 8, 2014
Messages
4
I apologize in advanced, I am very new to VBA.

Is it possible to create a macro (in my personal.xlsb) that actually creates a macro in another workbook? The macro in the personal.xlsb would go into a worksheet in another workbook, create a macro in a module, insert a form control button and assign the macro to the form control button. I've tried doing this while with the recorder and all it records is adding a button. It doesn't record anything else that I am doing in the VB editor screen.

Basically, I have a couple dozen workbooks that other people use that have an ActiveX button that don't work right now (because of the Dec. 2014 Microsoft update). I want to create a macro that goes in to these workbooks, deletes the ActiveX button(that's done below), inserts a new form control button (that's done below) and creates/assigns a new macro to it (is this possible?). Here is what I have...

Code:
Sub FixActiveX()
  
   'delete CommandButton
    Sheets("Week 1 Printable Schedule").Select
    ActiveSheet.Unprotect Password:="password"
    ActiveSheet.Shapes.Range(Array("CommandButton1")).Select
    Selection.Delete

''need to create macro here, macro name= W1RevertToMaster
'''code for W1ReverToMaster = Sheets("Week 2 Printable Schedule").Range("WeekSchedPrint2[[Monday]:[Sunday]]").Value = Sheets("Master Schedule").Range("Week[[Monday]:[Sunday]]").Value

   'add form control button
    ActiveSheet.Buttons.Add(763.5, 39, 73.5, 72.75).Select
    Selection.Characters.Text = "Click HERE to Revert to Master Schedule"
    With Selection.Characters(Start:=1, Length:=39).Font
        .Name = "Arial"
        .FontStyle = "Regular"
        .Size = 10
        .Strikethrough = False
        .Superscript = False
        .Subscript = False
        .OutlineFont = False
        .Shadow = False
        .Underline = xlUnderlineStyleNone
        .ColorIndex = xlAutomatic
    End With

    'need to assign W1RevertToMaster macro to form control button here

End Sub

Running excel 2013. Inserting the code to delete the Microsoft temp files for everyone else's computers is not really an option either at this point. Thanks for any insight you can offer. Thanks
 

Excel Facts

Can you AutoAverage in Excel?
There is a drop-down next to the AutoSum symbol. Open the drop-down to choose AVERAGE, COUNT, MAX, or MIN
Is it even possible to have a macro in the personal.xlsb file add code to a module in another workbook?
 
Upvote 0

Forum statistics

Threads
1,214,838
Messages
6,121,885
Members
449,057
Latest member
Moo4247

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