These files are of duration 10 seconds
In an excel file, I want a text box that should allow two characters.
The moment I open the excel file, it should take the cursor in that
textbox automatically.
If I type "A" in the textbox, it should play a.mp3 file without opening
the mp3 player. (I am using musicmatch/windows media player mp3 player)
If I type "B" as the second character in the textbox, it should erase
"A" which was entered earlier, show the character "B" in the text box
and play b.mp3 file.
If b.mp3 is playing and before the song is over (before 10 seconds) if
I enter C as the second character in the textbox, it should stop b.mp3
song and start plaing c.mp3
If I type any other character or if I press any other key besides A-Z,
it should stop the current song and should not play anything, it should
just erase value in the text box and place the cursor there and wait
for an A-Z input.
"Maxi" <maheshch...@gmail.com> schreef in bericht
news:1155372206.2...@p79g2000cwp.googlegroups.com...
Private Declare Function ShellExecute Lib "shell32.dll" Alias _
"ShellExecuteA" (ByVal hwnd As Long, ByVal lpOperation As String, ByVal _
lpFile As String, ByVal lpParameters As String, ByVal lpDirectory As String,
_
ByVal nShowCmd As Long) As Long
Private Sub wsBtnMP3_Click()
ShellExecute vbNull, "Open", "C:\a.mp3", vbNullString, "C:\", 0
End Sub
"moon" <hounga...@planet.nl> schreef in bericht
news:44ddabc4$0$2026$ba62...@text.nova.planet.nl...
In ThisWorkbook module:
Private Sub Workbook_Open()
ActiveSheet.OLEObjects("TextBox1").Object.MaxLength = 2
ActiveSheet.OLEObjects("TextBox1").Object.Value = ""
ActiveSheet.OLEObjects("TextBox1").Activate
End Sub
In Sheet module:
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
Private Declare Function GetShortPathName Lib "kernel32" _
Alias "GetShortPathNameA" (ByVal lpszLongPath As String _
, ByVal lpszShortPath As String, ByVal lBuffer As Long) As Long
Private Playing As Boolean, Current As String
Private Sub PlaySong(Play As Boolean, FullPathSong$, Optional Reprise& = 0)
On Error Resume Next
Call mciSendString("Stop MPFE", 0&, 0, 0)
Call mciSendString("Close MPFE", 0&, 0, 0)
If Not Play Then Exit Sub
Dim Song As String
Song = FullPathSong
If Dir(Song) = "" Then Exit Sub
Song = GetShortPath(Song)
Call mciSendString("Open " & Song & " Alias MPFE", 0&, 0, 0)
Call mciSendString("play MPFE from " & Reprise, 0&, 0, 0)
End Sub
Private Function GetShortPath(strFileName As String) As String
Dim lngRes As Long, strPath As String
strPath = String(165, 0)
lngRes = GetShortPathName(strFileName, strPath, 164)
GetShortPath = Left(strPath, lngRes)
End Function
Private Sub TextBox1_Change()
If TextBox1.Text = "" Then GoTo 1
If Len(TextBox1.Text) > 1 Then TextBox1.Text = Right$(TextBox1.Text, 1)
Const DefaultPath$ = "C:\MP3\"
If Dir(DefaultPath & TextBox1.Text & ".mp3") = "" Then
1: If Playing Then Playing = False Else Exit Sub
Else
Playing = True
Current = DefaultPath & TextBox1.Text & ".mp3"
End If
Call PlaySong(Playing, Current)
End Sub
MP
"Maxi" <maheshch...@gmail.com> a écrit dans le message de news:
1155372206.2...@p79g2000cwp.googlegroups.com...
The entire code works fine but when the song is playing, it gives me a
lot of hissing sound. When I play the file in Windows Media Player or
Musicmatch seperately it plays fine. It gives hissing sound only if I
play through this file.
Here is a link to download sample a.mp3, b.mp3 and c.mp3 file.
http://www40.brinkster.com/maxlott/mp3.htm
Any ideas??