Whinny like a horse!

SteveC

Board Regular
Joined
Mar 14, 2002
Messages
118
Howdy,
This is icing on the cake for me. I don't want to take away from the people who really have a need.

But if you're really bored . . .
I want to produce a horse sound (a whinny is good) when the number 1 is input in L13 thru L130. Also, it would be best if somehow this is not dependant on a different file, but rather it is included within this workbook. (The two other sheets will use it in the same range.)

I'm not finding anything that is clear to me.
Much obliged, pardner! (this is the West out here)
Gotta go out and repair the fences on the back forty now - before the cattle and the frogs git out...

Steve
 

Some videos you may like

Excel Facts

Will the fill handle fill 1, 2, 3?
Yes! Type 1 in a cell. Hold down Ctrl while you drag the fill handle.

Von Pookie

MrExcel MVP
Joined
Feb 17, 2002
Messages
13,686
Hi Steve! ::waves to the frogs so they don't attack::

I feel pretty secure in saying that I don't think you can attach a .wav file to the worksheet/book.

If nothing else, maybe distribute workbook/wav file together in a zip file or executable? You could either have the wav file go where you specify automatically or specify where it needs to go in some instructions or something.

Other than that, no clue.
 

Jack in the UK

Well-known Member
Joined
Feb 16, 2002
Messages
3,215
Hi Steve

You can embed the WAV file in excel as am image and call it to sound via VBA

Does this help,

Ivan F Moalas site details this, hes the guru that i know of in this field, see his site via profile

Jack
 

SteveC

Board Regular
Joined
Mar 14, 2002
Messages
118
Thank you to both Jack and Her Pookieness.
I'll check Ivan's site.
Steve & the Frogs
 

VoG

Legend
Joined
Jun 19, 2002
Messages
63,650

ADVERTISEMENT

This is written as a function - adapt to suit


Option Explicit
Option Base 1

Declare Function PlaySound Lib "winmm.dll" Alias _ "sndPlaySoundA" (ByVal WAVFILE As String, _ ByVal lNum As Long) As Long

Function Sound(WAVFILE As String)

Call PlaySound(WAVFILE, 0)

End Function











Declare Function PlaySound Lib "winmm.dll" Alias _ "sndPlaySoundA" (ByVal WAVFile As String, _ ByVal lNum As Long) As Long

in your code, place a statement like the following to play a WAV file:

Call PlaySound("C:WindowsMySound.wav", 0)

The following is a more elaborate example that allows you control of when your code begins and when the sound ends:

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 PlayWAV1()

Dim WAVFile

WAVFile = "C:WindowsMedialogoff"

'Finish sound before executing further code (SND_SYNC)

Call PlaySound(WAVFile, 0&, SND_SYNC Or SND_FILENAME) 'Use SND_ASYNC for the code to continue through the sound

End Sub
 

SteveC

Board Regular
Joined
Mar 14, 2002
Messages
118
Hi,
VoG - can your code be adapted to run from something imbedded, like Jack mentioned?

I'm really a novice and I have to admit that I'm not positive about where I'd substitute my info in your last code. I see where it reads FILENAME, and 3 lines down where it gives the path.

Steve
 

Ivan F Moala

MrExcel MVP
Joined
Feb 10, 2002
Messages
4,209
On 2002-11-01 02:47, SteveC wrote:
Howdy,
This is icing on the cake for me. I don't want to take away from the people who really have a need.

But if you're really bored . . .
I want to produce a horse sound (a whinny is good) when the number 1 is input in L13 thru L130. Also, it would be best if somehow this is not dependant on a different file, but rather it is included within this workbook. (The two other sheets will use it in the same range.)

I'm not finding anything that is clear to me.
Much obliged, pardner! (this is the West out here)
Gotta go out and repair the fences on the back forty now - before the cattle and the frogs git out...

Steve

Hi Steve, to do this you need to insert the sound as a packaged object and activate it like;

<PRE><FONT color=blue>Option Explicit</FONT>



<FONT color=#008000>'// Code To Worksheet
</FONT>


<FONT color=blue>Private <FONT color=blue>Sub </FONT></FONT>Worksheet_Change(<FONT color=blue>ByVal</FONT> Target <FONT color=blue>As</FONT> <FONT color=blue>Range</FONT>)

<FONT color=blue>Dim </FONT>MyRg <FONT color=blue>As</FONT> <FONT color=blue>Range</FONT>



<FONT color=blue>Set </FONT>MyRg = <FONT color=blue>Range</FONT>("L13:L130")



<FONT color=blue>Set </FONT>MyRg = Application.Intersect(MyRg, Target)

<FONT color=blue>If </FONT>MyRg.Cells.Count > 1<FONT color=blue> Then </FONT><FONT color=blue>Exit Sub</FONT>

<FONT color=blue>If </FONT>Not MyRg Is<FONT color=blue> Nothing</FONT> Then

<FONT color=blue>If </FONT>MyRg.Value = 1 Then

Whine

<FONT color=blue>End If</FONT>

<FONT color=blue>End If</FONT>



<FONT color=#008000>'// Code to STD Module
</FONT>


<FONT color=blue>Option Explicit</FONT>

<FONT color=#008000>'// Sound file from
</FONT>
<FONT color=#008000>'// http://www.thewavplace.com/animals.htm
</FONT>
<FONT color=#008000>'//
</FONT>


<FONT color=blue>Sub </FONT>Whine()

<FONT color=blue>Dim </FONT>Snd <FONT color=blue>As</FONT><FONT color=blue> Object</FONT>



<FONT color=blue>Set </FONT>Snd = ActiveSheet.OLEObjects(1)

DoEvents

Application.DisplayAlerts =<FONT color=blue> False</FONT>

Snd.Verb Verb:=xlPrimary

Application.DisplayAlerts =<FONT color=blue> True</FONT>

<FONT color=blue>Set </FONT>Snd =<FONT color=blue> Nothing</FONT>






</PRE>


I actually made an example workbook...email me if you would like the example.
NB:
 

Ivan F Moala

MrExcel MVP
Joined
Feb 10, 2002
Messages
4,209
Hi Steve
When I looed at this again the sound
will not play Asyncronously...ie sound will
play and all inputs will wait until finished
Not a hassle if you don't mind the sec or 2.
If not then you may need to
1) embed the sound file as an object
2) export it out (prgramatically)
3) then use API calls as above to play asyncronous......
 

Watch MrExcel Video

Forum statistics

Threads
1,122,554
Messages
5,596,811
Members
414,104
Latest member
imamalidadashzada

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Top