Improve company productivity with a Business Account.Sign Up

  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 291
  • Last Modified:

Open windows explorer on a CD from a form button

I need the VB code to make it so that I can create an "Explore the CD" button.  I just need to open up the CD in windows explorer for users to be able to browse through the files on it.  I have found things like this:


Shell ("D:" & "\explorer.exe")

but it did not work.  On top of that, I would like to not hard code the CD drive letter, and rather just have it say something like this:


"Open CDROM with explorer.exe"


3 Solutions
This code will find the cd-rom letter for you:
And then you can
shell ("start " & strCDLetter)
to bring up the explorer window for it...
Private Sub Command1_Click()
Dim oFSO        As Scripting.FileSystemObject
Dim oDrive      As Scripting.Drive
    Set oFSO = New Scripting.FileSystemObject
    For Each oDrive In oFSO.Drives
        If oDrive.DriveType = CDRom Then
            If oDrive.IsReady Then
                Call Shell("explorer.exe " & oDrive.DriveLetter & ":\", vbNormalFocus)
            End If
        End If
    Set oFSO = Nothing
End Sub
You will need reference to Microsoft Scripting runtime
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Anjinsan5Author Commented:
sirbounty - tried your solution, but it gives an error "file not found" on this line:

Shell ("start" & justonedrive$)

detected the drive letter just fine, but won't open up windows explorer.

u can use:

shell("explorer g:") for example.

i.e shell ("explorer " & strCDLetter)
Anjinsan5Author Commented:
thanks agj, that seems to have worked, now my only question is how to make sure that the explorer window has focus when it opens...
Anjinsan5Author Commented:
never mind, i got it.  Simply used the info above and wrote:

Call Shell("explorer " & justonedrive$, vbNormalFocus)

works like a charm...thanks so much everybody!
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now