Can anyone help with my code?
I have a workbook with a list of names, each name being the name of another workbook.
I want the code to loop through this list, opening each workbook in turn, then create a button within this workbook and then assign a macro from the opened workbook to the button. Save and close.
The macro name is the same for every workbook.
I can get it to almost do this, the problem being that it is assigning a macro from the workbook that I am using to run the original macro to create the buttons, if that makes sense.
The code is:
Workbooks.Open Filename Sheets("Upload").Visible = True Sheets("Upload").Select ActiveSheet.Unprotect Password:="123" 'Rows("60:62").Hidden = False ActiveSheet.Buttons.Add(Range("d58").Top, Range("d3").Left, 170.25, 25.25).Select strBname = Selection.Name OnAction = "Lock" - NAME OF MACRO TO BE ASSIGNED Selection.Characters.Text = "Lock" End With With Selection.Characters(Start:=1, Length:=10).Font .Name = "Times New Roman" .FontStyle = "Regular" .Size = 10 End With Range("B2").Select ActiveSheet.Protect Password:="123" 'Sheets("Upload").Visible = False ActiveWorkbook.Save Application.EnableEvents = False ActiveWorkbook.Close Next End Sub
I have left the loop for opening stores as this bit works.
If anyone can help me assign a macro from the opened workbook I will appreciate it