flyer
Mensagens : 2 Data de inscrição : 11/11/2011
| Assunto: Executar macro quando o sistema emitir um "beep" Sex Nov 11, 2011 8:16 pm | |
| Alguém tem idéia de como acionar uma macro a partir de um "beep" do sistema???? Obrigado! | |
|
alexandrevba
Mensagens : 1820 Data de inscrição : 13/07/2011 Localização : Serra - ES
| Assunto: Re: Executar macro quando o sistema emitir um "beep" Sex Nov 11, 2011 11:48 pm | |
| Boa noite!!! Veja ....se te ajuda. - Código:
-
Declare Function PlaySound Lib "winmm.dll" Alias "sndPlaySoundA" _ (ByVal lpszName As String, ByVal dwFlags As Long) As Long
'Put in Standard module, only, like: Module1!
Const SND_SYNC = &H0 Const SND_ASYNC = &H1 Const SND_FILENAME = &H20000
Then in the Sheet Module you want it to run or trigger on:
Sub PLAYWAV() 'Put in Sheet module, like: Sheet1. Dim wavefile, x
'List the "Drive:/Folder/filename.wav" for: wavefile! 'Or put the wavefile in the same folder as your WorkBook!
wavefile = "Ricochet.WAV"
Call PlaySound(wavefile, SND_ASYNC Or SND_FILENAME) End Sub
Or as an event:
Private Sub Worksheet_Change(ByVal Target As Range) 'Put in Sheet module, like: Sheet1.
If Target.Address <> "$S$7" Then Exit Sub If UCase(Target.Value) = "YES" Then
PLAYWAV
End If End Sub
Now you can also play MP3's through the Windows Media Player, with this code:
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 Declare Function FindWindow _ Lib "user32" Alias "FindWindowA" (ByVal lpClassName As String, _ ByVal lpWindowName As String) As Long
Sub myMP3Play() 'Sheet Module Code, like: Sheet1! Dim thisMP3 As String, MediaPlayer As String, theFile As String
theFile = "Q3.mp3" thisMP3 = "C:\Program Files\Windows Media Player\"
'Hide MediaPlayer and play! 'Call ShellExecute(FindWindow("xlMain", vbNullString), _ ' "Open", theFile, vbNullString, thisMP3, 0)
'Minimize MediaPlayer and play! 'Call ShellExecute(FindWindow("xlMain", vbNullString), _ ' "Open", theFile, vbNullString, thisMP3, 2)
'Show MediaPlayer and play! Call ShellExecute(FindWindow("xlMain", vbNullString), _ "Open", theFile, vbNullString, thisMP3, 1)
End Sub
Sub myMP3() 'Sheet Module Code, like: Sheet1! 'Note: Once the media player opens you must hit the play button! Dim myUnit, myTune
myTune = "C:\Program Files\Windows Media Player\Q3.mp3" myUnit = Shell("C:\Program Files\Windows Media Player\WMPLAYER.exe /Play" & myTune, 1)
End Sub
This is how to hook the midi player:
Declare Function mciSendString Lib "winmm" Alias "mciSendStringA" _ (ByVal lpstrCommand As String, ByVal lpstrReturnString As Any, _ ByVal uReturnLength As Long, ByVal hwndCallback As Long) As Long '// Function Discription: '// The mciSendString function sends a command string to an MCI device. '// The device that the command is sent to is specified in the command string. '// '// Success: '// Returns zero if successful or an error. '// The low-order word of the returned doubleword value contains the error return value. '// If the error is device-specific, the high-order word of the return value is the '// driver identifier; otherwise, the high-order word is zero. '// '// Parametre discriptions: '// -lpszCommand '// Address of a null-terminated string that specifies an MCI command string. '// For more information about the command strings, see Command Strings. '// '// -lpszReturnString '// Address of a buffer that receives return information. '// If no return information is needed, this parameter can be NULL. '// '// -cchReturn '// Size, in characters, of the return buffer specified by the lpszReturnString parameter. '// '// -hwndCallback '// Handle of a callback window if the "notify" flag was specified in the command string.
'Const sMidiFile As String = "C:\WINNT\MEDIA\Passport.mid" 'Const sMidiFile As String = "H:\Excel\Passport.mid" Const sMidiFile As String = "H:\Excel\Canyon.mid" 'Const sMidiFile As String = "H:\Excel\Midiex.mid" 'Const sMidiFile As String = "H:\Excel\Midibase.mid"
Dim Play
Sub Play_Midi() '// Discription: '// Plays a Midi sound File '// Specified by Const sMidiFile '// Play = mciSendString("play " & sMidiFile, 0&, 0, 0) If Play <> 0 Then MsgBox "Can't PLAY!"
End Sub
Sub Stop_Midi() Play = mciSendString("close " & sMidiFile, 0&, 0, 0) End Sub | |
|
flyer
Mensagens : 2 Data de inscrição : 11/11/2011
| Assunto: Re: Executar macro quando o sistema emitir um "beep" Sáb Nov 12, 2011 2:47 pm | |
| Grande presença! Vou testar! Um abraço Alexandre. Flyer | |
|
alexandrevba
Mensagens : 1820 Data de inscrição : 13/07/2011 Localização : Serra - ES
| Assunto: Re: Executar macro quando o sistema emitir um "beep" Sáb Nov 12, 2011 11:55 pm | |
| Boa noite!!!
Essa minha resposta foi uma copia de um MVP, apesar de ser muito próximo do que quer ..terá que ler os comentários em inglês...
Att.. | |
|
Conteúdo patrocinado
| Assunto: Re: Executar macro quando o sistema emitir um "beep" | |
| |
|