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

Last reviewed: July 30, 1997
Article 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 : kbmacroexample winword winword2 word6 word7 word95 kbmacro kbusage
Version : 2.x 6.0 6.0a 6.0c 7.0 7.0a
Platform : WINDOWS


THE INFORMATION PROVIDED IN THE MICROSOFT KNOWLEDGE BASE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND. MICROSOFT DISCLAIMS ALL WARRANTIES, EITHER EXPRESS OR IMPLIED, INCLUDING THE WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL MICROSOFT CORPORATION OR ITS SUPPLIERS BE LIABLE FOR ANY DAMAGES WHATSOEVER INCLUDING DIRECT, INDIRECT, INCIDENTAL, CONSEQUENTIAL, LOSS OF BUSINESS PROFITS OR SPECIAL DAMAGES, EVEN IF MICROSOFT CORPORATION OR ITS SUPPLIERS HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. SOME STATES DO NOT ALLOW THE EXCLUSION OR LIMITATION OF LIABILITY FOR CONSEQUENTIAL OR INCIDENTAL DAMAGES SO THE FOREGOING LIMITATION MAY NOT APPLY.

Last reviewed: July 30, 1997
© 1998 Microsoft Corporation. All rights reserved. Terms of Use.