I recently published an article about getting information on the latest earthquake of magnitude 5 or greater.
Please read this article to see how the core model was constructed.
One problem with this model is that since Excel’s web functions are non-volatile, a formula containing those functions must be recalculated by reentering the formula. I decided that an easier way was needed to trigger an update. I also recently published an article which utilized the hyperlink rollover technique.
I figured that this might be a good way to trigger a recalculation. And, since I was going to use a VBA function to be called from the hyperlink formula, I thought that adding audio functionality would be useful as well. Here is the hyperlink rollover formula used (in cell D5, named Recalculate). Since a rollover is required, the technique is not truly realtime.
=IFERROR(HYPERLINK(EarthQuakeAlert(),”Recalculate”),”Recalculate”)
And, here is the VBA function called by “rolling over” (passing the cursor over) that cell.
Function EarthQuakeAlert(Optional Person As String = “Him”, _
Optional Rate As Long = 1, Optional Volume As Long = 80)
Static xlApp As New Excel.Application
Dim Voc As SpeechLib.SpVoice
Set Voc = New SpVoice
Dim sAddress As String
‘Application.Volatile True
xlApp.CalculateFull
If Range(“d1”).Value = Range(“b3”).Value Then
MsgBox “No new earthquake > 5.0”
Else
With Voc
If Person = “Him” Then
Set .voice = .GetVoices.Item(0) ‘male
ElseIf Person = “Her” Then
Set .voice = .GetVoices.Item(1) ‘female
Else
End If
.Rate = Rate
.Volume = Volume
.Speak “New Earthquake Alert! ” & Range(“b5”).Value
End With
Range(“d1”).Value = Range(“b3”).Value
End If
EarthQuakeAlert = “Recalculate”
Set xlApp = Nothing
End Function
In order to use SpeechLib.SpVoice in the code, the correct reference (from Tools, References) must be added to the VBE as shown in the following figure.
In this figure is a picture of the earthquake model.
I hope that you find this useful. You can download the file here.