Announcement

Collapse
No announcement yet.

Vba Code To Open Cd Rom Device

Collapse
X
  • Filter
  • Time
  • Show
Clear All
new posts

  • Vba Code To Open Cd Rom Device



    Open CD-Rom drawer devices. Uses MCI.

    Thought this was some cool code for posting. Has many uses, like re-assigning your buddys A-Z sort in Excel to open his CD-Rom,,,He, He.
    Attached Files

  • #2
    Re: Vba Code To Open Cd Rom Device

    It certainly is a bit more advanced than what I have

    Code:
    Declare Sub mciSendStringA Lib "winmm.dll" (ByVal lpstrCommand As String, _
    ByVal lpstrReturnString As Any, ByVal uReturnLength As Long, _
    ByVal hWndCallback As Long)
    
    
    Sub OpenCDTray()
        mciSendStringA "Set CDAudio Door Open", 0&, 0, 0
    End Sub
    
    
    Sub CloseCDTray()
        mciSendStringA "Set CDAudio Door Closed", 0&, 0, 0
    End Sub

    Comment


    • #3
      Re: Vba Code To Open Cd Rom Device

      Good Morning Mudraker: I hope you don't mind but I borrowed your code for opening & closing the CD tray & modified it as follows. 1st I added a Userform with 2 commandbuttons on top of each other with the following code:
      Code:
      Private Sub CommandButton1_Click()
          Application.Run "OpenCDTray"
      End Sub
      
      Private Sub CommandButton2_Click()
          Application.Run "CloseCDTray"
      End Sub
      Private Sub UserForm_Initialize()
          CommandButton1.Visible = True
          CommandButton2.Visible = False
      End Sub
      then I added to your code as follows;
      Code:
      Declare Sub mciSendStringA Lib "winmm.dll" (ByVal lpstrCommand As String, _
      ByVal lpstrReturnString As Any, ByVal uReturnLength As Long, _
      ByVal hWndCallback As Long)
      Option Private Module
      Sub OpenCDTray()
          mciSendStringA "Set CDAudio Door Open", 0&, 0, 0
          MsgBox "What did you do? Please close your CD Tray so that you can continue!"
          UserForm1.CommandButton1.Visible = False
          UserForm1.CommandButton2.Visible = True
      End Sub
      
      Sub CloseCDTray()
          mciSendStringA "Set CDAudio Door Closed", 0&, 0, 0
          MsgBox "Thank You for closing me! Now you can proceed with whatever you wanted to do!"
          UserForm1.CommandButton2.Visible = False
          UserForm1.CommandButton1.Visible = True
          Unload UserForm1
      End Sub
      abbeville
      Templates & Calculators

      Comment


      • #4
        Re: Vba Code To Open Cd Rom Device

        Very nice.

        Comment


        • #5
          Re: Vba Code To Open Cd Rom Device

          Good sharing guys thanks to all of You

          jiuk

          Comment


          • #6
            Re: Vba Code To Open Cd Rom Device

            abbeville

            I certainly don't mind what you do to the code and it is not mine - I found it on the net

            Comment


            • #7


              Re: Vba Code To Open Cd Rom Device

              Good morning: My workbook was accidentally deleted so I had to build a new one. Like the "Six Million Dollar Man", better, faster, stronger. This time I used a userform with 1 command button.
              Code:
              Private Sub CommandButton1_Click()
                  Select Case CommandButton1.Caption
                  Case "Click Me"
                  Application.Run "OpenCDTray"
                  MsgBox "What DID you do? Please close my CD Tray so that we can continue!", 32
                  CommandButton1.Caption = "Close Tray"
                  Case "Close Tray"
                  MsgBox "Oops! My mistake! Try again.", 48
                  CommandButton1.Caption = "Retry"
                  Case "Retry"
                  MsgBox "Computer Malfunction!! My error! Try again!", 16
                  CommandButton1.Caption = "NOW what's wrong?"
                  Case "NOW what's wrong?"
                  MsgBox "I have no idea! Please retry again.", 16
                  CommandButton1.Caption = "Your move!"
                  Case "Your move!"
                  Application.Run "CloseCDTray"
                  
                  MsgBox "Congratulations! Thank You for finally closing me!" & vbCrLf & _
                  "Now we can proceed with whatever you wanted to do!", 48
              
                  End Select
              Code:
              Private Sub UserForm_Initialize()
                  CommandButton1.Caption = "Click Me"
              
              End Sub
              Code:
              Private Sub Workbook_Open()
                  Select Case Sheet1.Range("A1").Value
                  Case Is = ""
                  UserForm1.Show (vbModeless)
                  End Select
              End Sub
              and the original code:
              Code:
              Declare Sub mciSendStringA Lib "winmm.dll" (ByVal lpstrCommand As String, _
              ByVal lpstrReturnString As Any, ByVal uReturnLength As Long, _
              ByVal hWndCallback As Long)
              Option Private Module
              Sub OpenCDTray()
                  mciSendStringA "Set CDAudio Door Open", 0&, 0, 0
              
              
              End Sub
               
              Sub CloseCDTray()
                  mciSendStringA "Set CDAudio Door Closed", 0&, 0, 0
                  Unload UserForm1
              End Sub
              abbeville
              Templates & Calculators

              Comment

              Working...
              X