Adding Sound to Program Revisited

  • Thread starter Thread starter Carlton Patterson
  • Start date Start date
C

Carlton Patterson

Hello all,

I chap called Bob Phillips assisted me in adding sound to a program,
however when I tried to create my own program with sound it wouldn't
work. I was wondering if someone here could point out where I might be
going wrong. I keep on getting the error message : Sub or Function not
defined. I think its because I somehow haven't declared "playwavfile"
but I'm not sure. Any help would be appreciated.

Private Sub Worksheet_Calculate()
Static prevValue
If Range("I1").Value > prevValue Then
PlayWavFile "C:\Windows\Media\Windows XP Print complete"
prevValue = Range("I1").Value
End If
End Sub

Cheers

Carlton
 
Where have you stored the PlayWav File function? It, and the API
declaration, should be in the same module as the call, or as Public
definitions in a standard code module.
 
Hi Bob,

I didn't realise it needed to be stored - the file is in the directory
specified in the program.

I'm not sure how to declare a function.

Could you provide another example?

Cheers


Carlton
 
Carlton,

I will re-state the code.

Make sure that all of this code is stored in the worksheet code module of
the sheet that you will be testing I1 value. To do ths, right-click on the
sheet tab, select the View Code option from the menu, and paste the code in.

And also check that this file C:\Windows\Media\Microsoft Office
2000\Chimes.wav exists at this location on your machine, or change
accordingly.

Private Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" _
(ByVal lpszName As String, _
hModule As Long, _
ByVal dwFlags As Long) As Long

Private Sub Worksheet_Calculate()
If Range("I1").Value > 0 Then
PlayWavFile "C:\Windows\Media\Microsoft Office 2000\Chimes.wav"
End If
End Sub


Public Function PlayWavFile(WavFile As String) As String
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000
PlaySound WavFile, 0, SND_ASYNC Or SND_FILENAME
PlayWavFile = ""
End Function


--

HTH

RP
(remove nothere from the email address if mailing direct)
 
OK,

I'm trying to sort this out myself but still need your help.

I downloaded the following program:

Private Declare Function PlaySound Lib "winmm.dll" _
Alias "PlaySoundA" (ByVal lpszName As String, _
ByVal hModule As Long, ByVal dwFlags As Long) As Long

Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000

Sub PlayWAV()
WavFile = "chimes.wav"
WavFile = "C:\WINDOWS\Media\chimes.wav"
Call PlaySound(WavFile, 0&, SND_ASYNC Or SND_FILENAME)
End Sub


Can someone please help me incorporate the above into;

Private Sub Worksheet_Calculate()
Static prevValue
If Range("I1").Value > prevValue Then
prevValue = Range("I1").Value
End If
End Sub


Cheers

Carlton
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top