Open Windows Explorer and select item

  • Thread starter Thread starter R Avery
  • Start date Start date
R

R Avery

Is there any programmatic way to instantiate Windows explorer, and point it
to a path (without using IE)? If so, is it further possible to then select
an item in that instance, showing the user where a particular file is? Any
help would be greatly appreciated.
 
This is some code I used to get to a specific path. It may not be exactly
what you want, but you get the idea. I'm not sure if you can add the
filename or not, give it a try and let me know your results

Dim path1 As String, path2 As String
Dim fs As Object
Dim temp as Variant
Set fs = CreateObject("Scripting.FileSystemObject")
path1 = "G:\path1\" & ActiveCell.Value
path2 = "G:\path2\" & ActiveCell.Value
Select Case "True"
Case fs.folderexists(path1)
temp = Shell("EXPLORER.EXE /e,/root," & path1, vbNormalFocus)
Case fs.folderexists(path2)
temp = Shell("EXPLORER.EXE /e,/root," & path2, vbNormalFocus)
Case Else
MsgBox ("Folder " & ActiveCell.Value & " does not exist")
End Select
End Sub
 
Why not use the file open dialog:

chdrive "C"
ChDir "C:\My documents"
fname = Application.GetOpenFileName()
 
Thank you for this. It instantiates the windows explorer and goes to the
appropriate directory.
However, is it possible to then select an item in that window to point the
user to the correct document?

The reason i do not want to use file open dialog is that these files will
not be Excel files... they will be a combination of either: PDFs, DOCs,
TXTs, or TIFs.
 
I would recommend you check out the Microsoft knowledge base at the
following link
http://support.microsoft.com/default.aspx?scid=kb;en-us;130510&Product=wd2002
watch for word wrap
the article q130510 talks about the command-line switches for explorer. The
/e switch tells explorer to open in explorer view and the /root switch
specifies the root level folder to view. There is a switch /select which
allows sub object selection but I'm not sure if that is just for folders or
allows file also. Give it a try
Paul D
 
Well if I would have read the examples at the bottom I would have seen you
can select a file as per this example

explorer /select,c:\windows\calc.exe

Paul D
 
Back
Top