|
代码自己更新下,然后把公式中的自定义名称“科目”如图该一下:公式文件加密,不上附件了!
- Public 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
- Public Declare Function GetShortPathName Lib "kernel32" Alias "GetShortPathNameA" (ByVal lpszLongPath As String, ByVal lpszShortPath As String, ByVal cchBuffer As Long) As Long
- Dim t, x%, arr, b As Boolean
- Dim Mp3name As String
- Private Function ConvShortFilename(ByVal strLongPath$) As String
- Dim strShortPath$
- If InStr(1, strLongPath, " ") Then
- strShortPath = String(LenB(strLongPath), Chr(0))
- GetShortPathName strLongPath, strShortPath, Len(strShortPath)
- ConvShortFilename = Left(strShortPath, InStr(1, strShortPath, Chr(0)) - 1)
- Else
- ConvShortFilename = strLongPath
- End If
- End Function
- Public Sub MPlay(ByRef FileName As String)
- FileName = ConvShortFilename(FileName)
- mciSendString "close " & FileName, vbNullString, 0, 0
- mciSendString "open " & FileName, vbNullString, 0, 0
- mciSendString "play " & FileName, vbNullString, 0, 0
- End Sub
- Public Sub MStop(ByRef FileName As String)
- FileName = ConvShortFilename(FileName)
- mciSendString "stop " & FileName, vbNullString, 0, 0
- mciSendString "close " & FileName, vbNullString, 0, 0
- End Sub
- Sub 开始()
- With Sheet2
- If Sheet1.[L9] = "" Then
- MsgBox "请选择科目!"
- Sheet1.[L9].Select
- Exit Sub
- End If
- arr = .Range("a1:g7")
- For i = 1 To 7
- If Sheet1.[L9] = arr(1, i) Then x = i
- Next
- b = True
- Call 计时
- End With
- End Sub
- Sub 计时()
- If b = True Then
- Application.OnTime Now + TimeValue("00:00:01"), "计时"
- Sheet1.[L12] = Time
- For i = 2 To 7
- If arr(i, x) = Sheet1.[L12] Then
- Mp3name = ThisWorkbook.Path & "" & arr(i, 1) & ".mp3"
- MPlay (Mp3name)
- Sheet1.[l11] = arr(i, 1)
- t = arr(i, x) + TimeValue("00:00:10") '音乐播放20秒
- End If
- Next
- If t = Time Then MStop (Mp3name)
- End If
- End Sub
- Sub 停止()
- b = False
- MStop (Mp3name)
- End Sub
复制代码 |
|