View Full Version : [SOLVED:] Storing wav files in a workbook.
paulked
06-26-2015, 10:59 AM
I can embed .wav files and play them without opening media player but I was wondering if there was any way to keep the sounds in the same file as excel (like a picture).
Kenneth Hobs
06-26-2015, 11:06 AM
You lost me. If you embeded it, that OLEObject can then be used for the verbs allowed. What are you trying to do?
paulked
06-26-2015, 12:24 PM
I have this code to play the wav files
Option Explicit
Private Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As Long, ByVal dwFlags As Long) As Long
Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000
Sub PlayShort()
Dim WAVFile As String
'WAVFile = "blockshort.wav" - doesn't play when embedded
WAVFile = "C:\users\user\dropbox\blockshort.wav"
Call PlaySound(WAVFile, 0&, SND_ASYNC Or SND_FILENAME)
End Sub
Sub PlayLong()
Dim WAVFile As String
'WAVFile = "blockbusters.wav" - doesn't play when embedded
WAVFile = "C:\users\user\dropbox\blockbusters.wav"
Call PlaySound(WAVFile, 0&, SND_ASYNC Or SND_FILENAME)
End Sub
If I embed the two wav files and remove the paths from the procedures (as commented out) they don't play!
Kenneth Hobs
06-26-2015, 02:12 PM
See:
http://www.vbaexpress.com/forum/showthread.php?t=24370
http://www.vbaexpress.com/forum/showthread.php?t=37056
paulked
06-27-2015, 04:41 AM
Many thanks for that.
I've been put on 'home improvement' duties today, but I'll have a look at it later
Best regards
Paul Ked
paulked
06-27-2015, 07:27 PM
Sorry, but it not work...
Tries to open media player (don't want that), then gives errors...
"cannot open (????), access denied in (some temp directory)"
On some sheet, use the Excel menu Insert >> Object browse to your wav and insert it.
Sub PlayMyWav()
Sheets("Sheet with Wav Embedded").OLEObjects(1).Verb Verb:=xlPrimary
End Sub
If you rename the Object (the embedded wav) then you can use the name as the index to OLEObjects() and have more than one wav embedded on the same (hidden?) sheet
paulked
06-28-2015, 10:07 AM
Thank you very much SamT, I'm a happy bunny :hi:
Powered by vBulletin® Version 4.2.5 Copyright © 2025 vBulletin Solutions Inc. All rights reserved.