Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
Adding Sound to Program Revisited
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 *** Sent via Developersdex http://www.developersdex.com *** |
#2
Posted to microsoft.public.excel.programming
|
|||
|
|||
Adding Sound to Program Revisited
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. -- HTH Bob Phillips "Carlton Patterson" wrote in message ... 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 *** Sent via Developersdex http://www.developersdex.com *** |
#3
Posted to microsoft.public.excel.programming
|
|||
|
|||
Adding Sound to Program Revisited
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 *** Sent via Developersdex http://www.developersdex.com *** |
#4
Posted to microsoft.public.excel.programming
|
|||
|
|||
Adding Sound to Program Revisited
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) "Carlton Patterson" wrote in message ... 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 *** Sent via Developersdex http://www.developersdex.com *** |
#5
Posted to microsoft.public.excel.programming
|
|||
|
|||
Adding Sound to Program Revisited
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 *** Sent via Developersdex http://www.developersdex.com *** |
#6
Posted to microsoft.public.excel.programming
|
|||
|
|||
Adding Sound to Program Revisited
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 Private Sub Worksheet_Calculate() Static prevValue If Range("I1").Value prevValue Then prevValue = Range("I1").Value PlayWav End If End Sub The end result is that your sheet module should look the same as if you copied all the above code and pasted it into an empty sheet module -- Regards, Tom Ogilvy "Carlton Patterson" wrote in message ... 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 *** Sent via Developersdex http://www.developersdex.com *** |
#7
Posted to microsoft.public.excel.programming
|
|||
|
|||
Adding Sound to Program Revisited
OK,
while waiting for help I put this together but still couldn't get the sound to work! 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 Private Sub Worksheet_Calculate() Static prevValue If Range("I1").Value prevValue Then WavFile = "chimes.wav" WavFile = "C:\WINDOWS\Media\chimes.wav" Call PlaySound(WavFile, 0&, SND_ASYNC Or SND_FILENAME) prevValue = Range("I1").Value End If End Sub Carlton *** Sent via Developersdex http://www.developersdex.com *** |
#8
Posted to microsoft.public.excel.programming
|
|||
|
|||
Adding Sound to Program Revisited
Your code worked fine for me. (it performed as I would expect based on how
it is written). Do you have the code in the sheet module? Is your sound turned on? Is the value in I1 of the sheet containing the code increasing? Is calculation set to automatic? -- Regards, Tom Ogilvy "Carlton Patterson" wrote in message ... OK, while waiting for help I put this together but still couldn't get the sound to work! 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 Private Sub Worksheet_Calculate() Static prevValue If Range("I1").Value prevValue Then WavFile = "chimes.wav" WavFile = "C:\WINDOWS\Media\chimes.wav" Call PlaySound(WavFile, 0&, SND_ASYNC Or SND_FILENAME) prevValue = Range("I1").Value End If End Sub Carlton *** Sent via Developersdex http://www.developersdex.com *** |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
14 Day Average REVISITED | Excel Discussion (Misc queries) | |||
Help with averages revisited | Excel Worksheet Functions | |||
adding sound to an excel i.e. warning if data is negative | Excel Discussion (Misc queries) | |||
Adding an embedded sound? | Excel Discussion (Misc queries) | |||
Adding Sound to Program | Excel Programming |