Resting Anchor

The Anchorage

Personal website of Gregory K. Maxey, Commander USN (Retired)

Play Sound Byte When Document Opens
(A Microsoft Word Help & Tip page by Gregory K. Maxey)


The information, illustrations and code contained in my "Microsoft Word Tips" are provided free and without risk or obligation.

Click to acces PayPal Verification Service Click to acces PayPal Verification Service

However, the work is mine. If you use it for commercial purposes or benefit from my efforts through income earned or time saved then a donation, however small, will help to ensure the continued availability of this resource.

If you would like to donate, please use the appropriate donate button to access PayPal. Thank you!

This is just a short novelty Microsoft Word Tips & Microsoft Word Help page to show you how you can use a Windows API and play a short sound byte when a Word document is opened.

Copy and paste the following code to a standard module in the document VB project:

VBA Script:
Option Explicit
Private Declare Sub PlaySound Lib "winmm.dll" _
     (ByVal lpszName As String, _
     ByVal hModule As Long, _
    ByVal dwFlags As Long)
Private Const SOUND_FILENAME = &H20000

Sub AutoOpen()
Dim sndFileName As String
'Note:  Change the next line to point to your sound file.
sndFileName = "C:\Sound 1.wav"  
PlaySound sndFileName, 0&, SOUND_FILENAME
End Sub

Site Note icon See: Installing Macros for instructions on how to set up and use the macros provided in this Microsoft Word Help & Microsoft Word Tips page.

That's it! I hope you have found this tips page useful and informative.



Click to acces PayPal Verification Service Click to acces PayPal Verification Service

Do you want to make a payment for consulting work or donate to help support this site?

PayPal is a safe, easy way to pay online.

Use the appropriate currency "Donate" button to make a payment or donation.

Search my site or the web using Google Search Engine

Google Search Logo