![]() |
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? |
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 |
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" wrote in message oups.com... 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? |
Full folder path from BrowseForFolder
Beautiful, thanks Dave!
|
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? |
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" wrote in message ... 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 |
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" wrote in message ... 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 |
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 |
Full folder path from BrowseForFolder
Dave,
Thanks for that. I will have to noodle on it awhile. Jim Cone "Dave Peterson" 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. 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" wrote in message ... 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 |
All times are GMT +1. The time now is 10:22 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com