Can't call shape from Macro?

BBrandt

Board Regular
Joined
Jul 14, 2008
Messages
155
I've drawn a shape that I'd like to use to trigger a macro, and have another shape beneath it (same size, same shape, slightly different properties to simulate a pressed button). Just to test, I wanted to use a macro to shift around the order of the shapes, so I modified code I'd used for a similar purpose... but it doesn't work.

The shapes are named "RISAButtonState1" and "RISAButtonState2", here's the macro I want to trigger when I click the button:
Code:
Private Sub RISAButt*******()
[COLOR=seagreen]'Bring "pressed button" shape to front[/COLOR]
Shapes("RISAButtonState2").ZOrder msoBringToFront
 
newHour = Hour(Now())
newMinute = Minute(Now())
newSecond = Second(Now()) + 2
waitTime = TimeSerial(newHour, newMinute, newSecond) [COLOR=seagreen]'Wait 2 seconds[/COLOR]
Application.Wait waitTime
 
[COLOR=seagreen]'Return "unpressed button" shape to front[/COLOR]
Shapes("RISAButtonState1").ZOrder msoBringToFront
End Sub
When I run it it highlights the first line and gives me a "Sub or Function undefined" error.

Any idea what's causing that? Any help is greatly appreciated!

[edit: The sub is called RISA_Button_Click (with no underscores)... apparently o n c l i c k with no spaces gets censored? What?]
 
Last edited:

Excel Facts

Excel Can Read to You
Customize Quick Access Toolbar. From All Commands, add Speak Cells or Speak Cells on Enter to QAT. Select cells. Press Speak Cells.
I think that you need to qualify the sheet, something like

Code:
ActiveSheet.Shapes("RISAButtonState2").ZOrder msoBringToFront
 
Upvote 0
Yep, that did the trick, thanks! In the worksheet that I'd adapted the code for, the code was part of a Worksheet_Change event, so I guess the ActiveSheet part was implied in that case. Good to know.
 
Upvote 0

Forum statistics

Threads
1,214,858
Messages
6,121,960
Members
449,057
Latest member
FreeCricketId

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