Hi,
Add a code module to your VBA Project (by default 'Module1') and place the following code in it:
- Code: Select all
Option Explicit
Private Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As Long, ByVal dwFlags As Long) As Long
Public Sub WelcomeMessage()
Const SoundPath As String = "C:\My Music\"
Const SoundFile As String = "TheMessage.wav" ' must be a WAV file
Dim Sound As String
Sound = SoundPath & SoundFile
PlaySound(Sound, 0&, &H1 Or &H20000)
End Sub
You must assign real values to the two constants 'SoundPath' and 'SoundFile', and the SoundFile must be of WAV type.
Change your Workbook_Open event procedure to include one extra line:
- Code: Select all
Private Sub Workbook_Open()
WelcomeMessage
Worksheets(1).Activate
End Sub
The message will be played whenever you open the workbook. Loading the workbook will continue while the message is played and the user may be able to start work before the message has finished. If you wish to delay the opening until after the message has finished replace the last line of the 'WelcomeMessage' procedure with this one:
- Code: Select all
PlaySound(Sound, 0&, &H0 Or &H20000)
Have a great day!
Sisyphus
I do this for "honour and country" - much less of the latter, actually.
If I helped you, award points, plenty of them.
If I bored you, deduct points for being too long-winded. (I know, :lol)