Microsoft KB Archive/107690

From BetaArchive Wiki
Knowledge Base


Continue Macro Execution While Playing a .WAV File

Article ID: 107690

Article Last Modified on 10/11/2006



APPLIES TO

  • Microsoft Excel 5.0 Standard Edition



This article was previously published under Q107690

SUMMARY

The APPLICATION.SOUND.PLAY() or SOUNDNOTE.PLAY functions allow a macro to execute and play wave(.WAV) files. When you use these functions in a macro, Microsoft Excel must wait for the entire sound file to play before it can run the rest of the macro.

You can use the following

  • The Declare Functions, -and-


  • Microsoft Windows version 3.1(which includes MultiMedia Extensions), -and-


  • A sound card (such as the Windows Sound System or MediaVision's Pro Audio Spectrum),

to play the sound file with a macro. When you play the sound file in this manner, the macro will not have to wait for the wave file to finish playing. As soon as MultiMedia Extensions takes over playing the sound file, Microsoft Excel continues to execute the rest of the macro.

MORE INFORMATION

When you play the .WAV file this way, the sound file continues to play while the macro finishes executing, and it appears as if Microsoft Excel is performing two tasks at once. To demonstrate this behavior, play a .WAV file describing the contents of a dialog box and then display the dialog box. The following sample macro can be used in Microsoft Excel, version 5.0, for this purpose.

Microsoft provides examples of Visual Basic procedures for illustration only, without warranty either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose. This Visual Basic procedure is provided 'as is' and Microsoft does not guarantee that it can be used in all situations. Microsoft does not support modifications of this procedure to suit customer requirements for a particular purpose. Note that a line that is preceded by an apostrophe introduces a comment in the code--comments are provided to explain what the code is doing at a particular point in the procedure. Note also that an underscore character (_) indicates that code continues from one line to the next. You can type lines that contain this character as one logical line or you can divide the lines of code and include the line continuation character. For more information about Visual Basic for Applications programming style, see the "Programming Style in This Manual" section in the "Document Conventions" section of the "Visual Basic User's Guide."

WARNING: The Declare Function statements listed in the following macro are very sensitive. If used incorrectly, these functions may cause a general protection (GP) fault in Windows or cause serious software problems.

'The following two lines should be entered as a single line on a 'module
sheet
Declare Function sndPlaySound Lib "MMSYSTEM.DLL" (ByVal lpszSoundName
As String,_ ByVal wFlags As Integer) As Integer

Sub main()
   'Calls the sndPlaySound function and passes it the name of
   'the sound file to play
   Call sndPlaySound("c:\bat\wave\close.wav", 0)
End Sub
                



You can replace c:\bat\wave\close.wav with the path to any valid .wav file. This macro assumes the that you are using Microsoft Windows 3.1 and have a compatible sound card installed. Software sound drivers such as SPEAK.EXE will not give the desired results (these drivers must play the entire sound file before allowing Microsoft Excel to continue execution of the macro).

For more complete information about the sndPlaySound function of the MMSYSTEM.DLL, refer to the "Multimedia Programmer's Reference." This manual is part of the Microsoft Windows operating system version 3.1, Software Development Kit (SDK).


Additional query words: 5.0 blaster soundblaster wss creative labs XL5

Keywords: kbprb kbprogramming KB107690