No video

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

  • @LAZARSELVA
    @LAZARSELVA4 ай бұрын

    Thanks, its works great. Need to play audio if value changes How to do?

  • @LIV-FREE-VET
    @LIV-FREE-VET5 ай бұрын

    Wow, this actually worked. Thanks so much! Subscribing.

  • @gamespeopleplaygpp9543
    @gamespeopleplaygpp95435 ай бұрын

    thanks for the help in this!

  • @user-ki1pc6kw2r
    @user-ki1pc6kw2r Жыл бұрын

    Thanks bro, used it

  • @TheMuszekOkruszek
    @TheMuszekOkruszek Жыл бұрын

    How to play more sounds under more conditions??

  • @chrisk.9765
    @chrisk.97652 жыл бұрын

    Nice and good idea to make some fun...

  • @Exceltrainingvideos

    @Exceltrainingvideos

    2 жыл бұрын

    Yeah thanks

  • @hrp1800
    @hrp18002 жыл бұрын

    Nice. Thanks for sharing

  • @Exceltrainingvideos

    @Exceltrainingvideos

    2 жыл бұрын

    Thanks for watching

  • @stanstrong4655
    @stanstrong46552 жыл бұрын

    How about VBA code to change left/right audio balance or left and audio volume?

  • @skilldevelopment1639
    @skilldevelopment1639 Жыл бұрын

    shape perform any action for example, rotate or move with sound. it is possible?

  • @linaseptiani2994
    @linaseptiani29942 жыл бұрын

    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

    @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.

  • @mohammadhadian3720
    @mohammadhadian37202 жыл бұрын

    tnx

  • @chethankumar762
    @chethankumar7622 жыл бұрын

    I like it. 😎

  • @Exceltrainingvideos

    @Exceltrainingvideos

    2 жыл бұрын

    Thanks!

  • @ramneeksharma4226
    @ramneeksharma42262 жыл бұрын

    Sir, I'm unable to understand vba. What's the best way to start from scratch.

  • @Exceltrainingvideos

    @Exceltrainingvideos

    2 жыл бұрын

    Excel VBA tutorials in this playlist will help: kzread.info/head/PLFoKoDG_7gtKx1KcXPYOJ6APhcbNCRIDl

  • @CletoClips
    @CletoClips2 жыл бұрын

    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

    @Exceltrainingvideos

    2 жыл бұрын

    Before the end sub, you can call the sound macro or play a beep sound.

  • @CletoClips

    @CletoClips

    2 жыл бұрын

    @@Exceltrainingvideos Thank you

  • @kieranscott8085

    @kieranscott8085

    Жыл бұрын

    Application.Speech.Speak ("Done")

  • @aryklanees5373
    @aryklanees53732 жыл бұрын

    hi sir, is it possible to rename closed workbook sheet name thru vba (same name need to be applied for all wb)

  • @Exceltrainingvideos

    @Exceltrainingvideos

    2 жыл бұрын

    In the same folder?

  • @aryklanees5373

    @aryklanees5373

    2 жыл бұрын

    @@Exceltrainingvideos yes