Solved

Open windows explorer on a CD from a form button

Posted on 2004-09-13
7
271 Views
Last Modified: 2008-03-06
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:

On_Click

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:

On_Click

"Open CDROM with explorer.exe"

Thanks.

/.nick
0
Comment
Question by:Anjinsan5
7 Comments
 
LVL 67

Accepted Solution

by:
sirbounty earned 350 total points
Comment Utility
This code will find the cd-rom letter for you: http://www.devdos.com/vb/downloads/cdrom.zip
And then you can
shell ("start " & strCDLetter)
to bring up the explorer window for it...
0
 
LVL 8

Assisted Solution

by:mladenovicz
mladenovicz earned 50 total points
Comment Utility
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
    Next
   
    Set oFSO = Nothing
End Sub
0
 
LVL 8

Expert Comment

by:mladenovicz
Comment Utility
You will need reference to Microsoft Scripting runtime
0
What Should I Do With This Threat Intelligence?

Are you wondering if you actually need threat intelligence? The answer is yes. We explain the basics for creating useful threat intelligence.

 

Author Comment

by:Anjinsan5
Comment Utility
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.

/.nick
0
 
LVL 7

Assisted Solution

by:_agj_
_agj_ earned 100 total points
Comment Utility
u can use:

shell("explorer g:") for example.

i.e shell ("explorer " & strCDLetter)
0
 

Author Comment

by:Anjinsan5
Comment Utility
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...
0
 

Author Comment

by:Anjinsan5
Comment Utility
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!
0

Featured Post

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Background What I'm presenting in this article is the result of 2 conditions in my work area: We have a SQL Server production environment but no development or test environment; andWe have an MS Access front end using tables in SQL Server but we a…
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

772 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now