我有以下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