Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Build Macro to create a button, name it, and attach to existing macro

Status
Not open for further replies.

dyana

Technical User
Mar 26, 2002
27
US
I recorded a macro in Excel to create a button, that when involked would run a series of other macro. Unfortunately when I tried to run this recorded macro it would not work.

When recording this macro, I renamed the button from "button 1" to "Execute Process". Yet I think that the VBA code still sees it as button 1, because when I try to run it, it states that button 1 already exists.

How can I create the VBA code to create a button, then name it "Execute Process", then attach it to a macro called "Process"?

Thanks
 
when you record the macro, you can name it what you want. See if that works
[pc3]
[thumbsup2]
 
That's what I tried and it did not work.
 
The following will add a Button fron the Forms toolbox (not an ActiveX control from the Control Toolbox) and assign a procedure named Process to it.
Code:
    ActiveSheet.Buttons.Add(35.25, 19.5, 81, 21).Select
    With Selection
        .Name = "Execute Process"
        .OnAction = "Process"
    End With
The values in brackets determine the size and position of the button on the sheet, and may need some experimentation. Best way to experiment is to record creating the button exactly where you want it, and substitute the values obtained in the above.

A.C.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top