我使用此代碼播放聲音並在Excel中按下命令按鈕時打開用戶窗體。如何循環聲音
Private Sub CommandButton4_Click()
Call PlayIt
RequestAssistanceUserForm.Show
End Sub
Sub PlayTheSound(ByVal WhatSound As String)
If Dir(WhatSound, vbNormal) = "" Then
' WhatSound is not a file. Get the file named by
' WhatSound from the Windows\Media directory.
WhatSound = Environ("SystemRoot") & "\Media\" & WhatSound
If InStr(1, WhatSound, ".") = 0 Then
' if WhatSound does not have a .wav extension,
' add one.
WhatSound = WhatSound & ".wav"
End If
If Dir(WhatSound, vbNormal) = vbNullString Then
Beep ' Can't find the file. Do a simple Beep.
Exit Sub
End If
Else
' WhatSound is a file. Use it.
End If
sndPlaySound32 WhatSound, 0& ' Finally, play the sound.
End Sub
Sub PlayIt()
PlayTheSound "tada.wav"
End Sub
我想聲音循環,直到用戶窗體上的按鈕被按下來停止它,但我不知道如何實現這一點。如果你能指出我正確的方向(就如何編碼這一點),將非常感激。非常感謝
你是說聲音應該在循環中播放和其它活動可以並行發生的呢? –
@PankajJaju當用戶窗體被激活時,我不需要任何其他事件發生,當聲音循環時,所有內容都可以暫停,然後當按下按鈕時,所有事情都會恢復正常。 – user3049027