gpt4 book ai didi

excel - 如何循环播放声音

转载 作者:行者123 更新时间:2023-12-03 02:50:25 25 4
gpt4 key购买 nike

当在 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

我希望声音循环播放,直到按下用户窗体上的按钮来停止它,但我不确定如何实现这一点。如果您能够为我指出正确的方向(就如何编码而言),我将非常感激。非常感谢

最佳答案

您需要使用 const Const SND_LOOP = &H8 ,它将继续循环播放声音,直到下一次调用 PlaySound 为止。

我相信您正在使用的 API 是

Public Declare Function sndPlaySound32 _
Lib "winmm.dll" Alias "sndPlaySoundA" (ByVal lpszSoundName As String, _
ByVal uFlags As Long) As Long

使用我在下面使用过的那个。

试试这个

Declare Function PlaySound Lib "winmm.dll" Alias "PlaySoundA" _
(ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long

Const SND_LOOP = &H8
Const SND_ASYNC = &H1

Sub StartSound()
PlaySound "C:\Windows\Media\Chimes.wav", ByVal 0&, SND_ASYNC + SND_LOOP
End Sub

Sub StopSound()
PlaySound vbNullString, ByVal 0&, SND_ASYNC
End Sub

有关 API 的更多信息 HERE- My Fav stop for API's

关于excel - 如何循环播放声音,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20541815/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com