Tạo âm thanh khi bắn hàng trong gsheet online (1 người xem)

Liên hệ QC

Người dùng đang xem chủ đề này

Phuoctaifast

Thành viên mới
Tham gia
4/7/18
Bài viết
32
Được thích
9
Hi all !
Mình muốn tạo một âm thanh nhắc nhở khi nhập liệu sai hoặc đúng sẽ phát ra tiếng trong gsheet online.
Mong mấy bạn giúp đỡ !
Thanks all !
 
Code VBA play audio trên wikipedia:
https://en.wikibooks.org/wiki/Visual_Basic_for_Applications/Play_a_WAV_File_from_VBA
Mã:
Option Explicit
Public Declare Function sndPlaySound Lib "winmm.dll" _
        Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
           ByVal uFlags As Long) As Long

Sub TestPlayWavFile()
    'run this to play a sound wave (.wav) file
    
    Dim sPath As String
    
    'path to wave file - replace with your own
    sPath = "C:\Windows\Media\tada.wav"
    
    'test the no-wait feature
    PlayWavFile sPath, False
    MsgBox "This message box appears during the sound"
    
    'test the wait feature
    PlayWavFile sPath, True
    MsgBox "This message appears only after the sound stops"

End Sub

Function PlayWavFile(sPath As String, Wait As Boolean) As Boolean
    
    'make sure file exists
    If Dir(sPath) = "" Then
        Exit Function
    End If
    
    If Wait Then
        'hold up follow-on code until sound complete
        sndPlaySound sPath, 0
    Else
        'continue with code run while sound is playing
        sndPlaySound sPath, 1
    End If

End Function

Sub TestOtherSpeechProcs()
  
    'ReadIntegers "0123456789"
    'ExcelSpellOut "0123456789"
    ExcelSpeak "Any string can be spoken."
    
End Sub

Function ExcelSpeak(sIn As String) As Boolean
    'speaks any parameter string
    
    Application.Speech.Speak sIn,0,0,0
 
    ExcelSpeak = True

End Function

Function ExcelSpellOut(sIn As String) As Boolean
    'uses excel's speak function to read a string
    'one character at a time
    
    Dim n As Long, m As Long, sS As String

    For n = 1 To Len(sIn)
        DoEvents
        sS = Mid(sIn, n, 1) 'take one character
        Application.Speech.Speak sS, 0
    Next n
    
    ExcelSpellOut = True

End Function

Function ReadIntegers(sIn As String) As Boolean
    'general vba use
    'reads digits from parameter number string one by one
    'assumes that wav files for 0 to 9 exist as 0.wav to 9.wav

    Dim sS As String, sFdr As String, nLen As Long, n As Long

    'get folder for wav files
    sFdr = "C:\Users\Your Folder\"

    'sound out each digit
    For n = 1 To Len(sIn)   'loop through number string
        sS = Mid(sIn, n, 1) 'take one character
        
        'call wav file using sample value as part of name
        PlayWavFile sFdr & sS & ".wav", True
    
    Next n

    ReadIntegers = True

End Function
Ủng hộ website của mình:
http://vnguider.vn/forum/excel-vba/
 
Upvote 0
Web KT

Bài viết mới nhất

Back
Top Bottom