[英]Unable to play midi file using vba excel
enter image description here I'm trying to Play a midi file Using VBA editor.在此处输入图像描述我正在尝试使用 VBA 编辑器播放 MIDI 文件。 But After Assigning the Macro.. Its is Showing "Click OK when the MIDI file starts playing..."..But the song is not playing.
但是在分配宏后..它显示“MIDI文件开始播放时单击确定......”..但歌曲没有播放。 Both the song and excel are in same folder.
歌曲和excel都在同一个文件夹中。 So, Can anyone please tell where the mistake is?
那么,谁能告诉我错误在哪里? What went Wrong?
什么地方出了错?
Private Declare Function mciExecute Lib "winmm.dll" _
(ByVal lpstrCommand As String) As Long
Sub PlayMidiFile(Indiana_Jones_And_The_Last_Crusade__Main_Theme As String, Play As Boolean)
If Dir(Indiana_Jones_And_The_Last_Crusade__Main_Theme) = "" Then Exit Sub ' no file to play
If Play Then
mciExecute "play " & Indiana_Jones_And_The_Last_Crusade__Main_Theme ' start playing
Else
mciExecute "stop " & Indiana_Jones_And_The_Last_Crusade__Main_Theme ' stop playing
End If
End Sub
Sub TestPlayMidiFile()
PlayMidiFile "C:\Users\nulik\Desktop\music sairam", True
MsgBox "Click OK when the MIDI file starts playing..."
MsgBox "Click OK to stop playing the MIDI file..."
PlayMidiFile "C:\Users\nulik\Desktop\music sairam", False
End Sub
You need to define the complete path for the midifile with the midifile name and file extenstion (".mid" or ".midi"):您需要使用 midifile 名称和文件扩展名(“.mid”或“.midi”)定义 midifile 的完整路径:
PlayMidiFile "C:\Users\nulik\Desktop\music sairam\Indiana_Jones_And_The_Last_Crusade__Main_Theme.mid", True
PlayMidiFile "C:\Users\nulik\Desktop\music sairam\Indiana_Jones_And_The_Last_Crusade__Main_Theme.mid", False
EDIT: I got it to work, both on Excel 2010-32 bit and 2016-64bit:编辑:我让它在 Excel 2010-32 位和 2016-64 位上工作:
Add PtrSafe
in the "Private Declare Function" if you have 64-bit system.如果您有 64 位系统,请在“私有声明函数”中添加
PtrSafe
。 32-bit system could have PtrSafe
. 32 位系统可以有
PtrSafe
。 Execute " Sub TestPlayMidiFile
" to play midi file.执行“
Sub TestPlayMidiFile
”播放midi文件。
Private Declare PtrSafe Function mciExecute Lib "winmm.dll" _
(ByVal lpstrCommand As String) As Long
Sub PlayMidiFile(MidiFileName As String, Play As Boolean)
If Dir(MidiFileName) = "" Then Exit Sub ' no file to play
If Play Then
mciExecute "play " & MidiFileName ' start playing
Else
mciExecute "stop " & MidiFileName ' stop playing
End If
End Sub
Sub TestPlayMidiFile()
PlayMidiFile "G:\Till\robert_miles__fable__dream_remix__unknown.mid", True
MsgBox "Click OK when the MIDI file starts playing..."
MsgBox "Click OK to stop playing the MIDI file..."
PlayMidiFile "G:\Till\robert_miles__fable__dream_remix__unknown.mid", False
End Sub
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.