ExcelTip.Net留存知识帖 ---【注:附件之前被网盘供应商清空后,现已修复-现已修复-现已修复为本地下载!】
现在位置:首页 > 我的酷贴 > Excel VBA > VBA插放和停止MP3

VBA插放和停止MP3

作者:绿色风 分类: 时间:2022-08-18 浏览:91
楼主
winnie_xyh
Q:vba怎么播放音乐和停止音乐
A:代码如下:
  1. Private Declare Function mciSendString Lib "winmm.dll" Alias "mciSendStringA" (ByVal lpstrCommand As String, ByVal lpstrReturnString As String, ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long
  2. Private Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long

  3. Private Function ConvShortFilename(ByVal strLongPath$) As String
  4.     Dim strShortPath$
  5.     If InStr(1, strLongPath, " ") Then
  6.         strShortPath = String(LenB(strLongPath), Chr(0))
  7.         GetShortPathName strLongPath, strShortPath, Len(strShortPath)
  8.         ConvShortFilename = Left(strShortPath, InStr(1, strShortPath, Chr(0)) - 1)
  9.     Else
  10.         ConvShortFilename = strLongPath
  11.     End If
  12. End Function

  13. Public Sub Mp3Play(ByRef FileName As String)
  14.     FileName = ConvShortFilename(FileName)
  15.     mciSendString "close " & FileName, vbNullString, 0, 0
  16.     mciSendString "open " & FileName, vbNullString, 0, 0
  17.     mciSendString "play " & FileName, vbNullString, 0, 0
  18. End Sub




  19. Public Sub Mp3Stop(ByRef FileName As String)
  20.     FileName = ConvShortFilename(FileName)
  21.     mciSendString "stop " & FileName, vbNullString, 0, 0
  22.     mciSendString "close " & FileName, vbNullString, 0, 0
  23. End Sub
  1. Dim mp3file As Variant

  2. Private Sub CommandButton1_Click()
  3.     mp3file = ThisWorkbook.Path & "\混音版.mp3"
  4.     Sheet1.Mp3Stop (LastMp3File)
  5.     LastMp3File = mp3file
  6.     Sheet1.Mp3Play (mp3file)
  7. End Sub

  8. Private Sub CommandButton2_Click()
  9.     Sheet1.Mp3Stop (mp3file)
  10. End Sub

VBA添加音乐.rar
2楼
hylees
我要用来做贺卡
3楼
winnie_xyh
也是哦,可以做个漂亮的窗体,来放音乐!
4楼
liucq
不错,学习        

免责声明

有感于原ExcelTip.Net留存知识的价值及部分知识具有的时间限定性因素, 经与ExcelTip.Net站长Apolloh商议并征得其同意, 现将原属ExcelTip.Net的知识帖采集资料于本站点进行展示, 供有需要的人士查询使用,也慰缅曾经的论坛时代。 所示各个帖子的原作者如对版权有异议, 可与本人沟通提出,或于本站点留言,我们会尽快处理。 在此,感谢ExcelTip.Net站长Apolloh的支持,感谢本站点所有人**绿色风(QQ:79664738)**的支持与奉献,特此鸣谢!
------本人网名**KevinChengCW(QQ:1210618015)**原ExcelTip.Net总版主之一

评论列表
sitemap