Full folder path from BrowseForFolder

J

Jon

I am trying to create a script that utilizes the BrowseForFolder dialog
box. I want to have it return the full path of the selected folder
rather than just the folder name. Here is what I have so far:

Sub shellb()

Dim objShell
Dim objFolder

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.browseforfolder(0, "Choose folder
to be listed:", 0, 17)
If (Not objFolder Is Nothing) Then
Range("A3").Value = objFolder
End If
Set objFolder = Nothing
Set objShell = Nothing

End Sub

All this does is write the folder name to cell A3. Is there a way I
can get this script to record the full path to the folder I selected? I
have read some about the 'GetPathFromIDList' feature but I am not
familiar with it, any suggestions?
 
R

Ron de Bruin

Hi Jon

You can do it like this

Dim oApp As Object
Dim ofolder
Dim RootPath As String

Set oApp = CreateObject("Shell.Application")
'Browse to the folder
Set ofolder = oApp.BrowseForFolder(0, "Select folder", 512)
If ofolder Is Nothing Then Exit Sub
RootPath = ofolder.Self.Path
MsgBox RootPath
 
J

Jon

Now I would like to use that folder path and create a list of files and
their attributes (such as date created, size, type) and paste them into
my document. How would I go about doing this?
 
J

Jim Cone

Dave,
I give up, where does ".Self" come from?
It is not in the Windows Script Technologies 5.6 help file.
I have used objFolder.Path and objFile.Path without a hitch to return paths.
Very curious.
Regards,
Jim Cone
San Francisco, USA


"Dave Peterson" <[email protected]>
wrote in message
This worked ok for me:

Range("A3").Value = objFolder.self.Path


Jon wrote:>
 
D

Dave Peterson

A copy|pasted Jon's code into a module.

I put a watch on ObjFolder and stepped through the code. Then I expanded that
object in the watch window and saw Self--then I expanded that and saw what I
needed.
 
D

Dave Peterson

One way:

Option Explicit
Sub shellb()

Dim objShell
Dim objFolder

Set objShell = CreateObject("Shell.Application")
Set objFolder = objShell.browseforfolder _
(0, "Choose folder to be listed:", 0, 17)
If (Not objFolder Is Nothing) Then
Range("A3").Value = objFolder
Call ShowFiles(objFolder.self.Path)
End If
Set objFolder = Nothing
Set objShell = Nothing

End Sub

Sub ShowFiles(myFolderName As String)

Dim FSO As Object
Dim myFolder As Object
Dim myFile As Object
Dim iCtr As Long

Set FSO = CreateObject("Scripting.FileSystemobject")
Set myFolder = FSO.getfolder(myFolderName)

iCtr = 3
For Each myFile In myFolder.Files
iCtr = iCtr + 1
Cells(iCtr, "A").Value = myFile.Path
Cells(iCtr, "B").Value = myFile.Name
Cells(iCtr, "C").Value = myFile.datecreated
Cells(iCtr, "D").Value = myFile.Size
Next myFile

End Sub
 
J

Jim Cone

Dave,
Thanks for that. I will have to noodle on it awhile.
Jim Cone


"Dave Peterson" <[email protected]>
wrote in message
A copy|pasted Jon's code into a module.

I put a watch on ObjFolder and stepped through the code. Then I expanded that
object in the watch window and saw Self--then I expanded that and saw what I
needed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top