Can I pre-load wav file into memory on opening excel wb?

M

MikeZz

Hi,
I have a workbook that I want to have play certain wav files as alerts.
These are not the windows standard wav files so whenever an even triggers a
wav aleart, excel has to open the file and then play it.

This slows things down as the mouse icon turns into the "hour-glass" for a
second.

Is there a way to have excel either run the playsound in the background or
preload the file into memory so there is no wait?

Thanks!
 
C

Chip Pearson

You can't preload the sound file. However, a sound can be played
synchronously or asynchronously. In synchronous sound, the code will
pause execution until the sound has complete playing, In asychronous
sound, the wav is sent to the function but code continues to execute
while the sound is playing. E.g,

Public Declare Function sndPlaySound32 _
Lib "winmm.dll" _
Alias "sndPlaySoundA" ( _
ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long

Const PLAY_SOUND_SYNC As Long = 0& ' wait for completion
Const PLAY_SOUND_ASYNC As Long = 1& ' do not wait

Sub AAA()
sndPlaySound32 "C:\Windows\Media\chimes.wav", ASYNC
End Sub



Cordially,
Chip Pearson
Microsoft Most Valuable Professional
Excel Product Group, 1998 - 2009
Pearson Software Consulting, LLC
www.cpearson.com
(email on web site)
 
M

MikeZz

Hi Chip,
At first I was having difficulties but figured it out.
Your solution works perfectly as usual!

The only problem I have now is that the "KeepTime" and "AlarmSound"
functions I've found on the internet cause the mouse to blink to an hourglass
for just a fraction of a second. It doesn't seem to interupt the mouse
enough to mess with the functionality... but it's darn right agitating to see
it blink for that fraction of a second.

Any ideas on fixing that problem would be just fantastic!

Thanks again for the great assistance!

MikeZz
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top