?
Solved

Sound In Excel

Posted on 2003-03-26
3
Medium Priority
?
768 Views
Last Modified: 2008-03-06
Is there a way to write a macro that when an excel file is opened...a "wav" file is played on your computer?

For example, when anyone opens my excel file, I would like a voice to say "Welcome to Black Thunder"

Thanks.
0
Comment
Question by:vik1109
3 Comments
 
LVL 44

Expert Comment

by:bruintje
ID: 8210834
Hello Vik1109,

-open the vb editor with alt+f11
-next look for the thisworkbook icon
-double click it
-paste this code

Private Sub Workbook_Open()
  WorkRunACalls
End Sub

-next insert a new module
-place the code below into it

Declare Function sndPlaySoAnd32 Lib "winmm.dll" _
    Alias "sndPlaySoAndA" (ByVal lpszSoAndName _
    As String, ByVal uFlags As Long) As Long

Sub WorkRunACalls()
    On Error Resume Next
    ChDir "irgendwas"
    If Err = 76 Then GoTo ErrorsRoutine
    End
ErrorsRoutine:
    Call sndPlaySoAnd32("c:\windows\media\chimes.wav", 1)
End Sub

-next save and close
-save the workbook
-open it and try it out

HAGD:O)Bruintje
0
 

Author Comment

by:vik1109
ID: 8211425
Did not work.  I am using winnt and even changed the c:\windows\media\chimes.wav to the appropriate link in my case c:\winnt\media\chimes.wav

any other suggestions?  

the file does not give any errors either?
0
 
LVL 1

Accepted Solution

by:
tcalbaz earned 200 total points
ID: 8216376
Try using this code instead:
It works for me with Excel XP.

Private Declare Function sndPlaySound Lib "winmm.dll" _
Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long

Private Sub Workbook_Open()
    PlayWavFile "c:\foldername\soundfilename.wav", False
    MsgBox "You are supposed to see this dialog while the sound is playing..."
    PlayWavFile "c:\foldername\soundfilename.wav", True
    MsgBox "You are supposed to see this dialog after the sound is finished playing..."
End Sub

Sub PlayWavFile(WavFileName As String, Wait As Boolean)
    If Dir(WavFileName) = "" Then Exit Sub ' no file to play
    If Wait Then ' play sound before running any more code
        sndPlaySound WavFileName, 0
    Else ' play sound while code is running
        sndPlaySound WavFileName, 1
    End If
End Sub



0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
If Skype for Business came with your office 2016 or office 365 installation, you may find that it's almost impossible to either disable or remove it. The application will often launch with each start of Windows, even when explicitly configured not t…
The viewer will learn how to use the =DISCRINV command to create a discrete random variable, use this command to model a set of probabilities and outcomes in a Monte Carlo simulation, and learn how to find the standard deviation of a set of probabil…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

621 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question