Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Assign a sound to a variable

This is a shortened list of sounds in column R, sheet 1. And is the list for a data validation drop down in H1.

C:\Windows\Media\ir_end.wav
C:\Windows\Media\ringout.wav
C:\Windows\Media\Speech Misrecognition.wav

This is in Module 1:

Option Explicit

Private Declare Function sndPlaySound Lib "winmm.dll" _
Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long

Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_LOOP = &H8
Const SND_PURGE = &H40

Public Sub SoundPlayAsyncOnce(Sound As String)
'SND_SYNC to play assynchron
sndPlaySound Sound, SND_ASYNC
End Sub


This is in sheet1 vb editor:

Option Explicit

Private Declare Function sndPlaySound32 _
Lib "winmm.dll" _
Alias "sndPlaySoundA" ( _
ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long

Sub TingleTunes()

'Dim iSnd As string
'Set iSnd = Range("H1").Value
'SoundPlayAsyncOnce iSnd.Value
'SoundPlayAsyncOnce iSnd.Value

SoundPlayAsyncOnce ActiveCell.Value
End Sub

As is, it works fine to select a sound in R column and run Sub TingleTunes().

The commented out code lines is my attempt to select a sound from the drop down and run TingleTunes to play the selected sound.

I get object required error.

Thanks.
Howard
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Assign a sound to a variable

Hi Howard,

Am Tue, 7 May 2013 23:56:21 -0700 (PDT) schrieb Howard:

The commented out code lines is my attempt to select a sound from the drop down and run TingleTunes to play the selected sound.


in a standard module:

Option Explicit
Private Declare Function sndPlaySound Lib "winmm.dll" _
Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long

Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_LOOP = &H8
Const SND_PURGE = &H40

Public Sub SoundPlayAsyncOnce(Sound As String)
'SND_SYNC to play assynchron
sndPlaySound Sound, SND_ASYNC
End Sub

In the code module of sheet1:

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$H$1" Then
SoundPlayAsyncOnce Target.Value
End If
End Sub


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #3   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Assign a sound to a variable

On Wednesday, May 8, 2013 12:10:07 AM UTC-7, Claus Busch wrote:
Hi Howard,



Am Tue, 7 May 2013 23:56:21 -0700 (PDT) schrieb Howard:



The commented out code lines is my attempt to select a sound from the drop down and run TingleTunes to play the selected sound.




in a standard module:



Option Explicit

Private Declare Function sndPlaySound Lib "winmm.dll" _

Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _

ByVal uFlags As Long) As Long



Const SND_SYNC = &H0

Const SND_ASYNC = &H1

Const SND_LOOP = &H8

Const SND_PURGE = &H40



Public Sub SoundPlayAsyncOnce(Sound As String)

'SND_SYNC to play assynchron

sndPlaySound Sound, SND_ASYNC

End Sub



In the code module of sheet1:



Private Sub Worksheet_Change(ByVal Target As Range)

If Target.Address = "$H$1" Then

SoundPlayAsyncOnce Target.Value

End If

End Sub





Regards

Claus Busch

--

Win XP PRof SP2 / Vista Ultimate SP2

Office 2003 SP2 /2007 Ultimate SP2


As simple as that!

Thanks, Claus.

Regards,
Howard
  #4   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Assign a sound to a variable

Hi Howard,

Am Wed, 8 May 2013 01:08:18 -0700 (PDT) schrieb Howard:

As simple as that!


sound is declared as string. And only objects will be set.
If you want play your complete list in A then you could try it so:

Sub Test()
Dim iSnd As String
Dim i As Long
For i = 1 To 10
iSnd = Cells(i, 1).Value
SoundPlayAsyncOnce iSnd
Application.Wait Now + TimeValue("00:00:02")
Next
End Sub


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #5   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Assign a sound to a variable

On Wednesday, May 8, 2013 1:12:20 AM UTC-7, Claus Busch wrote:
Hi Howard,



Am Wed, 8 May 2013 01:08:18 -0700 (PDT) schrieb Howard:



As simple as that!




sound is declared as string. And only objects will be set.

If you want play your complete list in A then you could try it so:



Sub Test()

Dim iSnd As String

Dim i As Long

For i = 1 To 10

iSnd = Cells(i, 1).Value

SoundPlayAsyncOnce iSnd

Application.Wait Now + TimeValue("00:00:02")

Next

End Sub





Regards

Claus Busch

--

Win XP PRof SP2 / Vista Ultimate SP2

Office 2003 SP2 /2007 Ultimate SP2


Thanks again, Claus.

That snippet is a nice little demo.

Regards,
Howard


  #6   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 277
Default Assign a sound to a variable

On Wed, 8 May 2013 10:12:20 +0200, Claus Busch
wrote:

Hi Howard,

Am Wed, 8 May 2013 01:08:18 -0700 (PDT) schrieb Howard:

As simple as that!


sound is declared as string. And only objects will be set.
If you want play your complete list in A then you could try it so:

Sub Test()
Dim iSnd As String
Dim i As Long
For i = 1 To 10
iSnd = Cells(i, 1).Value
SoundPlayAsyncOnce iSnd
Application.Wait Now + TimeValue("00:00:02")
Next
End Sub


Regards
Claus Busch



It would be cool if it could "play" in a similar fashion as that of
"BURG" the boot loader app for Linux distros and other PC operating
systems. It uses numeric values for the tone frequencies and duration
numerics for the time. My PC plays "Fur Elise" when it boots. If I used
it at work, I could tell if someone reboots a bench PC or such (until
they press a key anyway).
  #7   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Assign a sound to a variable

Hi Claus,

I've got all codes and Public declares, Function etc... in place to play what ever is in "$H$1".

Below is a count down sub that works well on its own, and when the count down gets to whatever count down warning time selected by the user, the count down cell font turns red and continues counting down until 0, the enters "Time Up!"

I have tried to find a place in the count down code to place the equivalent
of "SoundPlayAsyncOnce Target.Value" so the code will play whatever is in
"$H$1" at the same time as the code turns the font red in the count down cell.

Private Sub Worksheet_Change(ByVal Target As Range)
If Target.Address = "$H$1" Then
SoundPlayAsyncOnce Target.Value
End If
End Sub


Option Explicit
Private Declare Sub Sleep Lib "kernel32" (ByVal dwMilliseconds As Long)
Public Status As Boolean

Private Sub cmdStart_Click()
Status = True
Dim i As Integer
Dim WarningTime As Integer
Dim Period As Double
Dim MyTime As Double

With Sheets("Main")
If (.Cells(5, 1) = "") Then
WarningTime = .Cells(5, 4)
Else
WarningTime = .Cells(5, 1)
End If

If (.Cells(8, 1) = "") Then
Period = .Cells(8, 4)
Else
Period = .Cells(8, 1)
End If
End With

If (Period < 0.01) Then Period = 0.01

With Sheets("Counter").Cells(2, 1)

.FormatConditions.Delete
.FormatConditions.Add xlCellValue, xlLessEqual, WarningTime


With .FormatConditions(1).Font
.Bold = True
.ColorIndex = 3

End With
.NumberFormat = Choose(Log(Period) / Log(10) + 3, "0.00", "0.0", "0")

.Value = Sheets("Main").Cells(2, 1).Value + Period

Sheets("Counter").Activate
While (.Value Period And Status)
.Value = .Value - Period
MyTime = .Value
For i = 1 To 100 * Period
Sleep 10
MyTime = MyTime - 0.01
If (MyTime <= 0) Then Exit For
DoEvents
Next i
Wend
If (.Value <= Period) Then .Value = "Time Up!"
End With
End Sub

Private Sub Worksheet_Change(ByVal Target As Range)
If (Target.Row = 2 And Target.Column = 1) Then
Cells(5, 1).Value = Cells(5, 4).Value
End If
End Sub

Thanks.
Howard
  #8   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Assign a sound to a variable

Hi Howard,

Am Wed, 8 May 2013 12:37:55 -0700 (PDT) schrieb Howard:

I have tried to find a place in the count down code to place the equivalent
of "SoundPlayAsyncOnce Target.Value" so the code will play whatever is in
"$H$1" at the same time as the code turns the font red in the count down cell.


on which sheet is the button "Start"?

Private Sub Worksheet_Change(ByVal Target As Range)
If (Target.Row = 2 And Target.Column = 1) Then
Cells(5, 1).Value = Cells(5, 4).Value
End If
End Sub


and on which sheet is this Worksheet_Change-Event?


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2
  #9   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 536
Default Assign a sound to a variable

On Wednesday, May 8, 2013 11:14:21 PM UTC-7, Claus Busch wrote:
Hi Howard,



Am Wed, 8 May 2013 12:37:55 -0700 (PDT) schrieb Howard:



I have tried to find a place in the count down code to place the equivalent


of "SoundPlayAsyncOnce Target.Value" so the code will play whatever is in


"$H$1" at the same time as the code turns the font red in the count down cell.




on which sheet is the button "Start"?



Private Sub Worksheet_Change(ByVal Target As Range)


If (Target.Row = 2 And Target.Column = 1) Then


Cells(5, 1).Value = Cells(5, 4).Value


End If


End Sub




and on which sheet is this Worksheet_Change-Event?





Regards

Claus Busch

--

Win XP PRof SP2 / Vista Ultimate SP2

Office 2003 SP2 /2007 Ultimate SP2


Hi Claus,

Button START in on sheet named Main.

The Change Event code I posted here is NOT used in this case. I just posted it to sort of show that I wanted to play a sound (which I can choose from a drop down) and play it in the timer count down code I posted. Sorry, I sure did not make that clear.

To add, I can't find if this statement - SoundPlayAsyncOnce - will stop the code to play the sound or plays the sound while the code continues. There is another similar statement like this one and I cannot find where I read which was which. In the end, I prefer to keep code running and play sound.

Howard
  #10   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 3,872
Default Assign a sound to a variable

Hi Howard,

Am Wed, 8 May 2013 23:39:17 -0700 (PDT) schrieb Howard:

Button START in on sheet named Main.

The Change Event code I posted here is NOT used in this case. I just posted it to sort of show that I wanted to play a sound (which I can choose from a drop down) and play it in the timer count down code I posted. Sorry, I sure did not make that clear.

To add, I can't find if this statement - SoundPlayAsyncOnce - will stop the code to play the sound or plays the sound while the code continues. There is another similar statement like this one and I cannot find where I read which was which. In the end, I prefer to keep code running and play sound.


try:
For i = 1 To 100 * Period
MyTime = MyTime - 0.01
SoundPlayAsyncOnce Sheets("Counter").Range("H1").Text
If (MyTime <= 0) Then Exit For
DoEvents
Next i


Regards
Claus Busch
--
Win XP PRof SP2 / Vista Ultimate SP2
Office 2003 SP2 /2007 Ultimate SP2


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
Assign Sub Name to a Variable Alan Excel Programming 3 October 10th 06 04:20 PM
Assign value to a variable name Gnarlodious Excel Discussion (Misc queries) 2 August 20th 06 07:10 AM
Assign my own sound from a list to a command button emil Excel Programming 1 June 30th 06 02:16 AM
Assign value to variable rroach Excel Discussion (Misc queries) 1 July 13th 05 05:24 AM
assign variable Tim Excel Programming 10 October 1st 04 07:33 PM


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

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

About Us

"It's about Microsoft Excel"