ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Sound Code (https://www.excelbanter.com/excel-programming/290652-sound-code.html)

bob

Sound Code
 
What am I missing so the sound will play when this command button is chosen

Private Sub CommandButton1_Click(
Sheets("Forecast").Selec
Sheets("Forecast").Range("A1").Selec
SoundNote.Import("C:/Program Files/Netscape/Communicator/Program/AIM/Sounds/dooropen.wav").Pla
End Su

Thank you for your help

Bob Phillips[_6_]

Sound Code
 
Bob,

What is SoundNote?

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Bob" wrote in message
...
What am I missing so the sound will play when this command button is

chosen?

Private Sub CommandButton1_Click()
Sheets("Forecast").Select
Sheets("Forecast").Range("A1").Select
SoundNote.Import("C:/Program

Files/Netscape/Communicator/Program/AIM/Sounds/dooropen.wav").Play
End Sub

Thank you for your help




Frank Kabel

Sound Code
 
Hi Bob
SoundNote was a functionality only available to Excel 5 / 95 and is no
longe available (I assume you're using Excel 97+)
So to play sound you have to use an APPI call.
Have a look at the following site for example code
http://j-walk.com/ss/excel/tips/tip59.htm

Frank

Bob wrote:
What am I missing so the sound will play when this command button is
chosen?

Private Sub CommandButton1_Click()
Sheets("Forecast").Select
Sheets("Forecast").Range("A1").Select
SoundNote.Import("C:/Program
Files/Netscape/Communicator/Program/AIM/Sounds/dooropen.wav").Play
End Sub

Thank you for your help




Frank Kabel

Sound Code
 
Bob Phillips wrote:
Bob,

What is SoundNote?


Hi Bob
an old, long forgotten feature of Excel 5/95 :-)
No longer available in Excel 97+. From John Walkenbach's site
(http://j-walk.com/ss/excel/tips/tip59.htm):
----
In Excel 5 and Excel 95, an easy way to add sound to your workbook is
to use a sound note -- a cell note that contains a WAV file. Select
Insert Note to display the Cell Note dialog box. Then click Import to
import a WAV file. Then you can play the sound with a VBA statement
such as:

Range("A1").SoundNote.Play-----Frank


bob

Sound Code
 
This doesn,t work. And have no idea how to make it work. Can you help

Private Sub CommandButton1_Click(
Sheets("Forecast").Selec
Sheets("Forecast").Range("A1").Selec

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

Const SND_SYNC = &H
Const SND_ASYNC = &H
Const SND_FILENAME = &H2000

Sub PlayWAV(
WAVFile = "dooropen.wav
WAVFile = ThisWorkbook.Path & "\" & WAVFil
Call PlaySound(WAVFile, 0&, SND_ASYNC Or SND_FILENAME
End Sub

Frank Kabel

Sound Code
 
Hi bob
I think you got an compiler error?. You have put the sub procedure
within another sub procedure.
Try putting the following in your respective module for your command
button:

Private Sub CommandButton1_Click()
WAVFile = "C:/Program
Files/Netscape/Communicator/Program/AIM/Sounds/dooropen.wav"
Call PlaySound(WAVFile, 0&, SND_ASYNC Or SND_FILENAME)
end sub


Put this in one module of your workbook
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

Frank




bob

Sound Code
 
Here is what I have done

I have this in Module 1

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

Const SND_SYNC = &H
Const SND_ASYNC = &H
Const SND_FILENAME = &H2000

And have this in sheet 8

Private Sub CommandButton1_Click(
WAVFile = "C:/Program/Files/Netscape/Communicator/Program/AIM/Sounds/dooropen.wav
Call PlaySound(WAVFile, 0&, SND_ASYNC Or SND_FILENAME
End Su

Then the error: Ambigous Name detecte

Im sorry I don't understand.

Frank Kabel

Sound Code
 
Hi Bob
try putting the Declare part also in your worksheet module (above the
commandButton_1 click procedure). so it should look like the following:
If you still have problems send me an email and I'll send you an
example sheet
Frank

------
Option Explicit
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

Private Sub CommandButton1_Click()
Dim WAVFile
WAVFile = "C:\winnt\media\chord.wav"
MsgBox "hallo2"
Call PlaySound(WAVFile, 0&, SND_ASYNC Or SND_FILENAME)
End Sub




Bob Phillips[_6_]

Sound Code
 
Bob,

The error you are getting sound as though you have something declared twice,
hence the ambiguous.

However, you also have a couple of other problems. If you have the PlaySound
API declared in Module 1, it needs to be Public not Private to be accessed
from other modules. Also, the Constants SND_ASYNC and SND_FILENAME are
being referenced in Sheet8, they need to be declared there, not in Module 1.
I would suggest just moving all of the Module 1 code to Sheet8, and removing
Module 1.

--

HTH

Bob Phillips
... looking out across Poole Harbour to the Purbecks
(remove nothere from the email address if mailing direct)

"Bob" wrote in message
...
Here is what I have done.

I have this in Module 1:

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

And have this in sheet 8:

Private Sub CommandButton1_Click()
WAVFile =

"C:/Program/Files/Netscape/Communicator/Program/AIM/Sounds/dooropen.wav"
Call PlaySound(WAVFile, 0&, SND_ASYNC Or SND_FILENAME)
End Sub

Then the error: Ambigous Name detected

Im sorry I don't understand.





All times are GMT +1. The time now is 10:27 AM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com