Play Sound in Excel Automatically Using VBA Macro
How to play a sound in Excel with a macro or VBA code to warn us, for example, of a wrong data entry. More details available on our website: www.exceltrain...
Here's the complete macro code:
Option Explicit
Private Declare PtrSafe Function sndPlaySound32 Lib "winmm.dll" _
Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Private Sub Worksheet_Change(ByVal Target As Range)
Dim highestGST As Long
highestGST = 28
If Range("B2").Value GREATER THAN highestGST Then
Call sndPlaySound32("C:\windows\media\Windows Error.wav", 1)
End If
End Sub
Private Declare PtrSafe Function sndPlaySound32 Lib "winmm.dll" _
Alias "sndPlaySoundA" (ByVal lpszSoundName As String, ByVal uFlags As Long) As Long
Sub PlaySound()
Dim lastrow As Long, i As Long
lastrow = Application.WorksheetFunction.CountA(Sheet1.Range("B:B"))
MsgBox lastrow
For i = 2 To lastrow
If Cells(i, 2) GREATER THAN 28 Then Call sndPlaySound32("C:\Windows\Media\Windows Exclamation.wav", &H8)
Next i
End Sub
NOTE: Replace GREATER THAN with an angular sign.
Пікірлер: 26
Thanks, its works great. Need to play audio if value changes How to do?
Wow, this actually worked. Thanks so much! Subscribing.
thanks for the help in this!
Thanks bro, used it
How to play more sounds under more conditions??
Nice and good idea to make some fun...
@Exceltrainingvideos
2 жыл бұрын
Yeah thanks
Nice. Thanks for sharing
@Exceltrainingvideos
2 жыл бұрын
Thanks for watching
How about VBA code to change left/right audio balance or left and audio volume?
shape perform any action for example, rotate or move with sound. it is possible?
If you move this excel file = you will no longer can play that sound. Cuz you lost the sound. Can you make the other way to put this sound inside to excel file, and then you make the script for this sound???
@timisgrindgames4663
Жыл бұрын
A bit long ago, but maybe its still helpful. If you place the Sound and Excel file in a folder and move the folder around it should work. You always get access to the folder path by Application.path (If im Not wrong) and you can finalize the path with the Audio files Name.
tnx
I like it. 😎
@Exceltrainingvideos
2 жыл бұрын
Thanks!
Sir, I'm unable to understand vba. What's the best way to start from scratch.
@Exceltrainingvideos
2 жыл бұрын
Excel VBA tutorials in this playlist will help: kzread.info/head/PLFoKoDG_7gtKx1KcXPYOJ6APhcbNCRIDl
I have several macros that run 30-90 seconds. I would like to add a beep when the macro is done running, rather than staring at the screen. Is there a way to do this?
@Exceltrainingvideos
2 жыл бұрын
Before the end sub, you can call the sound macro or play a beep sound.
@CletoClips
2 жыл бұрын
@@Exceltrainingvideos Thank you
@kieranscott8085
Жыл бұрын
Application.Speech.Speak ("Done")
hi sir, is it possible to rename closed workbook sheet name thru vba (same name need to be applied for all wb)
@Exceltrainingvideos
2 жыл бұрын
In the same folder?
@aryklanees5373
2 жыл бұрын
@@Exceltrainingvideos yes