Previous Topic

Next Topic

Book Contents

Book Index

Home Page

Play a Sound File From a Macro

Windows Script Host features can be used to play sound files to the speakers through Windows Media Player as follows:

Dim WshShell
' Create a WSH Shell object.
Set WshShell = _
CreateObject("WScript.Shell")
' Start Media Player and play file.
WshShell.Run _

"C:\Progra~1\Window~1\mplayer2.exe" + _
" /Play C:\sound.wav")

Notice that the name of the executable in the Run command uses eight character path names to avoid putting spaces in its filename. The location of Windows Media Player on any specific computer may vary, so adjust the command line if needed.

See Also

Automating Windows Tasks

Close the Call Monitor from a Macro

Run an Application from a Macro