View Single Post
  #7   Report Post  
Posted to microsoft.public.excel.programming
Howard Howard is offline
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