+ Reply to Thread
Results 1 to 9 of 9

Full folder path from BrowseForFolder

  1. #1
    Jon
    Guest

    Full folder path from BrowseForFolder

    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?


  2. #2
    Dave Peterson
    Guest

    Re: Full folder path from BrowseForFolder

    This worked ok for me:

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


    Jon wrote:
    >
    > 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?


    --

    Dave Peterson

  3. #3
    Ron de Bruin
    Guest

    Re: Full folder path from BrowseForFolder

    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


    --
    Regards Ron de Bruin
    http://www.rondebruin.nl


    "Jon" <[email protected]> wrote in message news:[email protected]...
    >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?
    >




  4. #4
    Jon
    Guest

    Re: Full folder path from BrowseForFolder

    Beautiful, thanks Dave!


  5. #5
    Jon
    Guest

    Re: Full folder path from BrowseForFolder

    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?


  6. #6
    Jim Cone
    Guest

    Re: Full folder path from BrowseForFolder

    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
    news:[email protected]...
    This worked ok for me:

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


    Jon wrote:>
    > 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?


    --

    Dave Peterson

  7. #7
    Dave Peterson
    Guest

    Re: Full folder path from BrowseForFolder

    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.



    Jim Cone wrote:
    >
    > 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
    > news:[email protected]...
    > This worked ok for me:
    >
    > Range("A3").Value = objFolder.self.Path
    >
    > Jon wrote:>
    > > 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?

    >
    > --
    >
    > Dave Peterson


    --

    Dave Peterson

  8. #8
    Dave Peterson
    Guest

    Re: Full folder path from BrowseForFolder

    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

    Jon wrote:
    >
    > 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?


    --

    Dave Peterson

  9. #9
    Jim Cone
    Guest

    Re: Full folder path from BrowseForFolder

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


    "Dave Peterson" <[email protected]>
    wrote in message
    news:[email protected]...
    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.



    Jim Cone wrote:
    >
    > 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
    > news:[email protected]...
    > This worked ok for me:
    >
    > Range("A3").Value = objFolder.self.Path
    >
    > Jon wrote:>
    > > 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?

    >
    > --
    >
    > Dave Peterson


    --

    Dave Peterson

+ Reply to Thread

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts

Search Engine Friendly URLs by vBSEO 3.6.0 RC 1