play object (audio file) when active cell is ""

AlexPi

Board Regular
Joined
Apr 4, 2011
Messages
104
Hi All,

I am having trouble getting this to work. I am close, but probably missing something. I am trying to play a wav file when the active cell is U18. When the user selects this cell, I want the audio file to play. When I use the code below, it works when I have the cell selected and run the macro but I do not want to have to run the macro. I'd like to it run automatically whenever the cell is selected.

Code:
Sub play_audio()



   If ActiveCell = Range("U18") Then
          ActiveSheet.Shapes("Object 39").Select
    Selection.Verb Verb:=xlPrimary
    End If
End Sub

Thank you!
 

Excel Facts

How to fill five years of quarters?
Type 1Q-2023 in a cell. Grab the fill handle and drag down or right. After 4Q-2023, Excel will jump to 1Q-2024. Dash can be any character.
You can use the SelectionChange event handler for your worksheet. Right-click the sheet tab for your sheet, select View Code, and place the following code in the code module for the sheet...

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Address <> "$U$18" Then Exit Sub
    Me.Shapes("Object 39").Verb Verb:=xlPrimary
End Sub

Note that Target refers to the selected cell, and the keyword Me refers to the sheet.

Hope this helps!
 
Upvote 0
Getting close! I now get a "runtime error 438 object doesn't support this property or method" on the line below. Any ideas?

Code:
[COLOR=#333333]Me.Shapes("Object 39").Verb Verb:=xlPrimary[/COLOR]
 
Upvote 0
I think we need to refer to the OLEFormat property of the Shapes object...

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Address <> "$U$18" Then Exit Sub
    Me.Shapes("Object 39")[COLOR=#ff0000].OLEFormat[/COLOR].Verb Verb:=xlPrimary
End Sub
 
Upvote 0
I think we need to refer to the OLEFormat property of the Shapes object...

Code:
Private Sub Worksheet_SelectionChange(ByVal Target As Range)
    If Target.Address <> "$U$18" Then Exit Sub
    Me.Shapes("Object 39")[COLOR=#ff0000].OLEFormat[/COLOR].Verb Verb:=xlPrimary
End Sub


That did it! Thank you!
 
Last edited:
Upvote 0

Forum statistics

Threads
1,223,711
Messages
6,174,025
Members
452,542
Latest member
Bricklin

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