How to play sound file without opening media player?

zoso

Well-known Member
Joined
Oct 23, 2003
Messages
725
Hi everyone

I have a .wav file embedded in a worksheet which runs on opening the file. I'm running Excel 2003, and the workbook still worked fine when I upgraded to Excel 2007. When I run Windows XP the sound file plays, and the worksheet opens where I'd previously been using it, which is perfect.

However, when I run the workbook in Vista the sound file still plays, but Excel now locates the embedded .wav file and then opens Windows Media Player (version 11), neither of which I want to happen!

Here's the relevant section of the code:
Code:
Private Sub Workbook_Open()

Sheets("Training Log").Select
Range("A20000").End(xlUp).Offset(0, 0).Select
ActiveSheet.Calendar1.Value = Date 'sets date to today's date

ActiveSheet.Shapes("BornToRun").Select
Selection.Verb Verb:=xlPrimary

Dim Wait As Boolean
I hope you can help - thank you!
 

Excel Facts

What did Pito Salas invent?
Pito Salas, working for Lotus, popularized what would become to be pivot tables. It was released as Lotus Improv in 1989.
Zoso

Think you have to store the wav and reference it, rather than embed it and play it. I am in the process of converting all my wavs (lots) from the Selection.Verb Verb:=xlPrimary method. I save the wav somewhere then use:

Code:
Private Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As Long, ByVal dwFlags As Long) As Long

   Dim WAVFile As String
Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000
Dim WinDirEnv As String
    WinDirEnv = Environ("Windir") + "\"[code]

then to play the file:

[code]WAVFile = WinDirEnv & "\..\PPR v8\images\YOUR WAV NAME.wav"
Call PlaySound(WAVFile, 0&, SND_ASYNC Or SND_FILENAME)[code]


Derek
 
Upvote 0
zoso, can you pleas tell me how you found the name of the embedded object "BornToRun" in the sheet where you embedded it?

does this work with .mp3 files embedded too?
 
Upvote 0
SOLVED AT LONG LAST!

I abandoned the idea of the embedded sound file and went with Joe Was' fantastic solution, as follows:

I copied the wav file to D:\MY FILES\My Sounds

Then copied into This Workbook, Open Event:

Dim wavefile, x

wavefile = "D:\MY FILES\My Sounds\BornToRun.wav"
'Whichever path is appropriate

Call PlaySound(wavefile, SND_ASYNC Or SND_FILENAME)

And created a module called BornToRun with the following, copied exactly:

Declare Function PlaySound Lib "winmm.dll" Alias "sndPlaySoundA" _
(ByVal lpszName As String, ByVal dwFlags As Long) As Long

Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000

Many many thanks Joe
 
Upvote 0

Forum statistics

Threads
1,215,095
Messages
6,123,072
Members
449,093
Latest member
ripvw

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