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

BlondieC

New Member
Joined
Feb 9, 2016
Messages
39
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.
 

RickXL

MrExcel MVP
Joined
Sep 9, 2013
Messages
4,314
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,
 

BlondieC

New Member
Joined
Feb 9, 2016
Messages
39
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?
 

mole999

Moderator
Joined
Oct 23, 2004
Messages
9,899
you could always do something phonic with SPEAK, mind you they have to have speakers turned on
 

BlondieC

New Member
Joined
Feb 9, 2016
Messages
39
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
 

RickXL

MrExcel MVP
Joined
Sep 9, 2013
Messages
4,314
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
 

mole999

Moderator
Joined
Oct 23, 2004
Messages
9,899
more like TEA AY DEE AY (TA DA)
 
Last edited:

BlondieC

New Member
Joined
Feb 9, 2016
Messages
39
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.
 

RickXL

MrExcel MVP
Joined
Sep 9, 2013
Messages
4,314
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,
 

Forum statistics

Threads
1,081,537
Messages
5,359,380
Members
400,526
Latest member
Brook1083

Some videos you may like

This Week's Hot Topics

  • VBA (Userform)
    Hi All, I just would like to know why my code isn't working. Here is my VBA code: [CODE=vba]Private Sub OKButton_Click() Dim i As Integer...
  • List box that changes fill color
    Hello, I have gone through so many pages trying to figure this out. I have a 2020 calendar that depending on the day needs to have a certain...
  • Remove duplicates and retain one. Cross-linked cases
    Hi all I ran out of google keywords to use and still couldn't find a reference how to achieve the results of a single count. It would be great if...
  • VBA Copy and Paste With Duplicates
    Hello All, I'm in need of some input. My VBA skills are sub-par at best. I've assembled this code from basic research and it works but is...
  • Macro
    is it possible for a macro to run if the active cell value is different to the value above it
  • IF DATE and TIME
    I currently use this to check if date has passed but i also need to set a time on it too. Is it possible? [CODE=vba]=IF(B:B>TODAY(),"Not...
Top