Using VBA to assign a macro to button

  • Thread starter GBExcel via OfficeKB.com
  • Start date
G

GBExcel via OfficeKB.com

I've searched through several posts but can't find a solution that helps me.
Here is what I am trying to do:

I have a button with an attached macro that imports a data table from a sheet
for the user to edit. When the user is done he must select a save button,
which is attached to a macro that copies the data table back to its original
place with the new data. All works well to this point.

However, There are many data tables that need to be brought in by means of
macro attached buttons. Once the user is done, each needs to be saved back to
its original location when the user selects the save button. This means that
the save button needs to be assigned a new save macro when each new table is
brought in. The save button's name is Chevron 41.

So if I bring in TABLE_A I need to be able to add a line of code to its macro
that sets button Chevron 41 to use macro SAVE_TABLE_A.

If I bring in TABLE_B I need to be able to add a line of code to its macro
that sets button Chevron 41 to use macro SAVE_TABLE_B.

Etc.

Here is the code that does not work:

' [NOW ASSIGN A SAVE MACRO TO THE SAVE BUTTON]
Application.CutCopyMode = False
' Selection.OnAction = "SAVE_TABLE_A_Save"

<<< This produces a debug error message so I tried this.....>>>>

ActiveSheet.Shapes("Chevron_41").OnAction = "SAVE_TABLE_A_Save"
Range("A11").Select

<<< This produces a message that says item with name was not found.>>>

Any help would be appreciated.

GBExcel
 
G

GBExcel via OfficeKB.com

I think I've found the answer. I needed to use a control button rather than a
shape button. The control works.

GBExcel
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top