?
Solved

Sound In Excel

Posted on 2003-03-26
3
Medium Priority
?
763 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
Outlook for dependable use in a very small business   This article is about using the Outlook application (part of Microsoft Office) in a very small business, or for homeowners where dependability and reliability are critical requirements. This …
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…
Learn how to create and modify your own paragraph styles in Microsoft Word. This can be helpful when wanting to make consistently referenced styles throughout a document or template.

764 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