Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 95
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 1,120
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 95
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 11,272
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 95
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 95
Default 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   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 27,285
Default 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
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
14 Day Average REVISITED F. Lawrence Kulchar Excel Discussion (Misc queries) 4 September 8th 08 11:54 PM
Help with averages revisited TimJames Excel Worksheet Functions 6 March 10th 08 12:20 PM
adding sound to an excel i.e. warning if data is negative CDG Excel Discussion (Misc queries) 6 March 11th 06 10:39 PM
Adding an embedded sound? Terry Pinnell Excel Discussion (Misc queries) 0 September 5th 05 12:50 PM
Adding Sound to Program Carlton Patterson Excel Programming 18 April 24th 05 11:59 PM


All times are GMT +1. The time now is 05:05 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"