WD: How to Play a .wav Sound File from Word for Windows

ID: Q89316


The information in this article applies to:
  • Microsoft Word for Windows, versions 2.0, 2.0a, 2.0a-CD, 2.0b, 2.0c, 6.0, 6.0a, 6.0c
  • Microsoft Word for Windows 95, versions 7.0, 7.0a


SUMMARY

The "More Information" section of this article includes an example of a macro you can use to play a .wav sound file.


MORE INFORMATION

NOTE: Microsoft provides macros "as is" without warranty of any kind, either expressed or implied, including but not limited to the implied warranties of merchantability and/or fitness for a particular purpose.

Word for Windows 95, version 7.x


'These declarations must be on one line.
'Place them above the Sub Main.

   Declare Function sndPlaySoundA Lib "winmm" \ 
   (lpszSoundName$, wFlags As Long) As Long
   Declare Function GetWindowsDirectoryA Lib \ 
   "Kernel32"(WinDir$, nSize As Long) As Long

   Sub MAIN
      Windir$ = String$(255, "X")
      N = GetWindowsDirectoryA(WinDir$, 255)
      N = sndPlaySoundA(WinDir$ + "\tada.wav", 0)
   End Sub 

Using Microsoft Windows version 3.1


      '** Calling dynamic-link libraries**
   Declare Function sndPlaySound Lib "mmsystem.dll" \ 
   (lpszSoundName$, wFlags As Integer) As Integer
   Declare Function GetWindowsDirectory Lib \ 
   "Kernel"(WinDir$, nSize As Integer) As Integer

   Sub MAIN
      '*Create a variable large enough to store the Windows path.
      Windir$ = String$(255, "X")
      '*Store the path to the Windows directory in WinDir$ variable.
      N = GetWindowsDirectory(WinDir$, 255)
      '*Load and Play the sound.
      N = sndPlaySound(WinDir$ + "\tada.wav", 0)
   End Sub 
NOTE: This macro assumes that your computer has a sound driver and does not check if the driver is loaded.

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: winapi mpc multimedia multi- media personal pc word7 word6

Keywords : kbmacro kbusage kbmacroexample winword word6 winword2 word7 word95
Version : WINDOWS:2.0,2.0a,2.0a-CD,2.0b,2.0c,6.0,6.0a,6.0c,7.0,7.0a
Platform : WINDOWS
Issue type :


Last Reviewed: November 4, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.