LinkBack Thread Tools Search this Thread Display Modes
Prev Previous Post   Next Post Next
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2
Default The specified device is not open or not recognized by MCI -"mciSendStringA", VBA

The following is the code (Form_Load), executed from MS Excel (and MS
Word). The "sndPlaySoundA" function from the "winmm.dll" works fine.
What am I missing? Thanks

Public Declare Function mciSendString Lib "winmm.dll" Alias
"mciSendStringA" (ByVal _
lpszCommand As String, ByVal lpszReturnString As String, ByVal
cchReturnLength _
As Long, ByVal hwndCallback As Long) As Long
Public Declare Function mciGetErrorString Lib "winmm.dll" Alias
"mciGetErrorStringA" (ByVal _
fdwError As Long, ByVal lpszErrorText As String, ByVal
cchErrorText As Long) As Long

' cribbed from code for playing a MIDI file
' Use the MCI to play or stop playback of a MIDI file. The file C:
\Music\canyon.mid
' is opened when the form opens. The Play and Stop buttons behave as
you'd expect. The
' only potential surprise is that the current position is not reset
when playback stops; it
' behaves just as pausing playback would. The file closes when the
form unloads.

' If anything goes wrong in the example, display a message box with
' the MCI error message text.

Sub Form_Load()
' Open the file "C:\Music\canyon.mid" for later use in the
example.
' Give it an alias of "canyon" so we don't need to refer to the
filename again.
Dim errcode As Long ' MCI error code

errcode = mciSendString("open D:\Documents and Settings\me\Desktop
\test.wav", "", 0, 0)
If errcode < 0 Then DisplayError errcode
End Sub

Sub cmdPlay_Click()
' Begin playback of the MIDI file when this button is pressed.
Dim errcode As Long ' MCI error code

errcode = mciSendString("play canyon", "", 0, 0)
If errcode < 0 Then DisplayError errcode
End Sub

Sub cmdStop_Click()
' Stop playback of the MIDI file when this button is pressed.
' The position within the file does not move back to the
beginning.
Dim errcode As Long ' MCI error code

errcode = mciSendString("stop canyon", "", 0, 0)
If errcode < 0 Then DisplayError errcode
End Sub

Sub Form_Unload(Cancel As Integer)
' Close the MIDI file when the form unloads. This is important,
because the
' MIDI driver can only work with one file at a time. There's no
need to check
' for an error here, since we're just closing the file.
Dim errcode As Long ' MCI error code

errcode = mciSendString("close canyon", "", 0, 0)
End Sub

Sub DisplayError(ByVal errcode As Long)
' This subroutine displays a dialog box with the text of the MCI
error. There's
' no reason to use the MessageBox API function; VB's MsgBox
function will suffice.
Dim errstr As String ' MCI error message text
Dim retval As Long ' return value

' Get a string explaining the MCI error.
errstr = Space(128)
retval = mciGetErrorString(errcode, errstr, Len(errstr))
' Remove the terminating null and empty space at the end.
errstr = Left(errstr, InStr(errstr, vbNullChar) - 1)

' Display a simple error message box.
retval = MsgBox(errstr, vbOKOnly Or vbCritical)
End Sub
 
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Unable to open a 82 KB XLSM file due to "Too many different cellformats" & "Converter failed to open the file." errors. Phillip Pi Excel Discussion (Misc queries) 0 April 23rd 09 08:53 PM
Unable to open a 82 KB XLSM file due to "Too many different cellformats" & "Converter failed to open the file." errors. Phillip Pi Setting up and Configuration of Excel 0 April 23rd 09 08:53 PM
Excel not recognized using "open with" command on text files mrwawa Excel Discussion (Misc queries) 1 March 30th 09 05:17 PM
How to disable "New" "open" menu items in Excel 2007 Aruna Akella Excel Programming 1 March 26th 08 05:13 AM
conditional formula to show "open" or "closed" SBS Excel Worksheet Functions 6 January 28th 06 01:48 AM


All times are GMT +1. The time now is 09:48 PM.

Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
Copyright ©2004-2025 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"