我有以下Excel场景方框Excel表:停止VBA来执行时的功能
A1具有 “A” 的值,B2 = “B”,C3 = “C”
但它们是可互换的。
在工作簿路径有含名为A.wav,B.wav和C.wav
WAV文件两个子文件夹在底部的代码可以让我以回放按钮点击射击宏中的wav文件播放()。
我的问题是,虽然函数正在执行我无法编辑Excel中的单元格,我真的需要!它看起来有点像这样
https://gifyu.com/images/GIF8d5e1.gif
感谢您的帮助!
代码Audioplayback:
Option Explicit
#If VBA7 Then
Public Declare PtrSafe Function PlaySound Lib "winmm.dll" _
Alias "sndPlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
#Else
Public Declare Function PlaySound Lib "winmm.dll" _
Alias "sndPlaySoundA" (ByVal lpszName As String, ByVal hModule As Long, ByVal dwFlags As Long) As Long
#End If
Const SND_SYNC = &H0
Const SND_ASYNC = &H1
Const SND_FILENAME = &H20000
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 = ThisWorkbook.Path & "\stimuli\" & "\1second\" & 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.
MsgBox "Could not find the file in the Path: " & WhatSound
Exit Sub
End If
Else
' WhatSound is a file. Use it.
End If
PlaySound WhatSound, 0&, SND_ASYNC Or SND_FILENAME ' Finally, play the sound.
End Sub
Sub PlayIt()
PlayTheSound (Range("A1").Value)
PlayTheSound (Range("B1").Value)
PlayTheSound (Range("C1").Value & "e")
End Sub
'BYVAL HMODULE作为LongPtr'。如果你的办公室是x64,可能是原因。 – GSerg
@GSerg如果我删除'BYVAL HMODULE作为LongPtr'只有调用'PlaySound WhatSound,SND_ASYNC或者SND_FILENAME'我只听到最后的wav文件'PlayTheSound(范围( “C1”)。价值与 “E”)' – McTell
你有'ByVal hModule As Long'。正确的事情是'ByVal hModule As LongPtr'。 – GSerg