Copying VBA events with buttons

  • Thread starter Thread starter Bill Butcher
  • Start date Start date
B

Bill Butcher

I am using the same VB buttons on many of my slides for
navigating to different chapters. I don't want to add
these same VB buttons manually each time I create a new
slide. I am programmatically copying these buttons from a
hidden slide on demand when the user navigates to an
associated chapter. The problem is the event does not
come along with the button when I do the copy. Is there
away to programmatically attach code (subroutine)/event to
the buttons when I copy them over?

Thanks for any help in advance,

Bill
 
My guess is that you are using the CommandButton from the Control Toolbox.
When you double-click that button to insert code behind it, you get a
"Private" subroutine that is unique to that slide. Therefore, the
subroutine does not come over with the button when copied to a new slide.

Try this method:

1. Click "Autoshapes" on the Drawing Toolbar, select "Action Buttons",
"Custom Button". When the Action Settings dialog box opens up just close
it.

2. Press ALT-F11 to enter the VBE window. Insert a Module in the VBE
window, move the macro from your slide to the Module. Change the "Private"
to "Public".

3. Close the VBE window, right-click on your new button and select "Action
Settings". In the "Run macro" dropdown select your new macro.

Now when you copy this button to other slides, the Action Settings assigned
to it goes with it. Hope this helps!

Bill Foley
www.pttinc.com
 
Bill,

Your approach does work. I have been considering this
rather than using the CommandButton from the toolbox. The
only issue with this approach is that I can't control the
custom autoshape(looks like a button) visually in the same
manner as a regular CommandButton.

Depending on the conditions I am adding a checkbox image
to the button and at other times I am disabling the
button. These properties are easy to deal with on a
CommandButton. On an autoshape I think I can do something
that will look similar, but I'll have to do it with
additional textboxes and other shapes to get the same
effect.

Thanks,

Bill
 
You can right-click on your action button and select "Add text". You can
probably do this programmatically using VBA if you really need to. What you
would want to do is to assign an object name to your button. I can post
some code that one of the MVPs posted awhile back if that will help. Sounds
like what you are trying to do is pretty intense. Good Luck. If we can be
of any assistance, holler back.

Bill Foley
www.pttinc.com
 
Hello Bill,
In the Autoshape collection check out the 'Action Setting: Custom' shape
which can be used to get the visual effect of a button click. To create a
disabled effect you can superimposed another shape over it with a disabled
state colour and no action setting.

You will also find the code to detect which shape was clicked on the
following page www.mvps.org/skp/vba.html
 
Back
Top