Play embedded wav file when workbook opens but without showing the media player

BlondieC

New Member
Joined
Feb 9, 2016
Messages
41
Running Excel 2013.

I've done quite a bit of searching on this one this morning and from most of the info I read it doesn't look like this can be done. However, most of the info was years old so I'm hoping over the years something changed and I will be able to have this work successfully.

I don't include sound in my Excel reports but this is a special case. We have a product launch of sorts coming up and for the first report I send out on these products I wanted to have a wav play when the end user opens the workbook.

I have the wav embedded and some code and it works with one exception... the media player pops up asking with an "Open Package Contents" window asking "Do you want to open this file?, Open or Cancel".

I would really prefer if for the end user it just played without being prompted by the Media Player.

My code is placed in "ThisWorkbook".

Code:
Private Sub Workbook_Open()Application.DisplayAlerts = False
ActiveSheet.Shapes("Object 1").Select
Selection.Verb Verb:=xlPrimary
Application.DisplayAlerts = True
End Sub

Thank you.
 

Excel Facts

Excel motto
Not everything I do at work revolves around Excel. Only the fun parts.
Hi,

This works with .wav files in Windows 10 64bit:

Code:
Declare Function sndPlaySound Lib "winmm.dll" Alias "sndPlaySoundA" _
        (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long

Sub WAVPlay()
    Dim X As Long
    X = sndPlaySound("C:\Windows\Media\Windows Shutdown.wav", CLng(&H3))
End Sub
It uses a Windows routine directly but is called from VBA.

I am not sure where I found the original code but it might have been here: https://support.microsoft.com/en-us/kb/86281

If you change the &H3 into an &H2 it will wait for the sound to finish before continuing with the next instruction.

Regards,
 
Upvote 0
Hi Rick - thank you for your post. This will work with an embedded wav (object) even though it still references a file on the C: drive?
 
Upvote 0
you could always do something phonic with SPEAK, mind you they have to have speakers turned on
 
Upvote 0
Thank you Mole999 - I wasn't aware of the SPEAK feature until this morning when I was looking for a solution to my post. I will be reading more about it as I think I could put it to some good use.

you could always do something phonic with SPEAK, mind you they have to have speakers turned on
 
Upvote 0
I had thought of using speech instead of a wav file but when I tried the William Tell overture it seemed to be a bit lacking. :)

Code:
Sub WilliamTell()
    With Application.Speech
        .Speak ("Titty dum titty dum titty durm durm durm")
    End With
End Sub
 
Upvote 0
more like TEA AY DEE AY (TA DA)
 
Last edited:
Upvote 0
The wav I want to use is the opening from Star Trek with voice and sound so I'm not sure how it'll work with SPEAK.
 
Upvote 0
Hi Rick - thank you for your post. This will work with an embedded wav (object) even though it still references a file on the C: drive?


Sorry, no. Note to self: I must read the question before answering. :(

The problem is that Excel modifies the original sound file when it is embedded and does not provide an easy way to reconstitute it. There are various attempts to extract embedded files on the internet but you need to know how Microsoft has changed the file when it was embedded so you can undo it.

I have noticed the same problem with embedded pictures as well. Basically, the easy way to do it would be to keep any required files in the same folder as the workbook. If you need to distribute them you could zip them up.

Plan B. As a .xlsm file is already a zip file it may be possible to hack your sound file into there. However, that will probably not be a trivial exercise either.

Plan C would be to switch off the security check that puts up the confirmation screen.

I don't think there is an easy answer, sorry.

Regards,
 
Upvote 0

Forum statistics

Threads
1,223,912
Messages
6,175,341
Members
452,638
Latest member
Oluwabukunmi

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