I’m trying to get a cell to play a sound file that I have based on hitting a number, in this case 0 (zero). The add sound or audio feature under the other tab is not what I need since I need this to be automatic. Any help is greatly appreciated.
The IF clause is normally used to insert a value in a cell depending on the outcome of the IF test, one value for True and another for False.
You can however cause a function to be executed on the outcome of the test. You can create in Basic your own Function which can be called by the IF clause.
Put the Basic code below in the Calc Document using the Tools>Macros>Organise Macros>LibreOffice Basic. Click on your Calc Document name to display the Module. If you do not have any Macros in the Document create New Module.
Function MAKESOUND()
Beep
End function
In a blank Cell in the Spreadsheet put the Formula:-
=IF(D1=10,MAKESOUND())
replacing D1=10
with the Cell Reference=0
This will sound a beep when that Cell becomes 0.
This Function will bring up a Message Box when the IF criteria is met :-
Function MESS()
Test ="Cell Value is zero"
msgbox Test
End Function
replacing MAKESOUND with MESS in the Cell Formula.
To play a sound file instead of the “Beep” you will need to investigate how to do this in Basic. The code for this would need to be placed in a Basic Function as for “MAKESOUND” or “MESS”.
EDITED
To play an Audio File the Function is :-
Function PLAYFILE()
Shell("C:\Program Files (x86)\Windows Media Player\wmplayer.exe",2,"Full path to Audio File")
End Function
This will play the Audio File in Windows Media Player.
You may need to change the path to Windows Media Player depending on the version of Windows, or use another program to play the File.
Using the MESS Function is useful as you can not proceed with doing anything in the Spreadsheet until you have cancelled the Message. You could combine the Message and Play File in one Function.