![]() |
Embed Folder Treeview Or Windows Explorer On UserForm
Hello.
I'd like to create a UI where my users can graphically navigate through folder lists and select files. I don't want to programmatically invoke the Windows Explorer unless there's a way to embed it on a Userform (I don't want it in a seperate window). I looked at the TreeView control, and it looks like it will satisfy at least the folder browsing part, but I seem to recall that there's a control somewhere that's already set up to display folders in a similar fashion. I can't for the life of me remember what it is, though. And advice/pointers would be appreciated. I don't want to reinvent the wheel using a TreeView if there's another option. Thanks. -- Hmm...they have the Internet on COMPUTERS now! |
Embed Folder Treeview Or Windows Explorer On UserForm
the GetOpenFileName Method is, I think, what you are thinking of. Here is a
function I wrote for selecting a file ( I wrote it to be run from Access, so it creates an Excel object; you can skip that if you are running it in Excel): Public Function GetFile(Types As Byte, Optional FPath As String, Optional Prompt As String) As String ' Function to open file selection dialog box, return selected file path and name ' NOTE: Must include reference to the Microsoft Excel Object Library to use its ' File dialog box as an object ' ' Types will have bits set according to the types of files being searched for: ' (note: these were set by me, can be modified or extended) ' 00000001 (AllFiles,&H1) All Files ' 00000010 (TextFiles,&H2) for Text Files,*.txt ' 00000100 (PLMFiles,&H4) for PLM download files,*.rpt ' 00001000 (CSVFiles,&H8) for Comma Separated Values,*.csv ' 00010000 (ExcelFiles,&H10) for Excel Files,*.xls ' 00100000 (AccessFiles,&H20) for Access Files,*.mdb ' 01000000 (&H40) RESERVED ' 10000000 (&H80) RESERVED ' Any other choice, e.g. Types = 0, will give "All Files" ' User can "OR" these choices to get multiple file types ' FPath is the default file path ' Header is what will appear as the dialog box title ' Must declare an object variable as an Excel Application to allow the use of ' the Excel file selection dialog ' (ONLY if not run in Excel, just use Application object if you are already in Excel) Dim AppXL As New Excel.Application Dim FilText, FilTypes As String Dim Heading As Variant AppXL.DefaultFilePath = FPath If Prompt = "" Then Heading = "SELECT FILE" Else Heading = Prompt FilText = "" FilTypes = "" ' Set the FileFilter based on the Types specified If ((Types And &H20) = &H20) Then FilText = "ACCESS" If ((Types And &H20) = &H20) Then FilTypes = "*.mdb" If ((Types And &H10) = &H10) Then If FilText = "" Then FilText = FilText & "EXCEL" Else _ FilText = FilText & ";EXCEL" If FilTypes = "" Then FilTypes = "*.xls" Else _ FilTypes = FilTypes & ";*.xls" End If If ((Types And &H8) = &H8) Then If FilText = "" Then FilText = FilText & "Comma-Separated Values" Else _ FilText = FilText & ";Comma-Separated Values" If FilTypes = "" Then FilTypes = "*.csv" Else _ FilTypes = FilTypes & ";*.csv" End If If ((Types And &H4) = &H4) Then If FilText = "" Then FilText = FilText & "PLM Download Files" Else _ FilText = FilText & ";PLM Download Files" If FilTypes = "" Then FilTypes = "*.rpt" Else _ FilTypes = FilTypes & ";*.rpt" End If If ((Types And &H2) = &H2) Then If FilText = "" Then FilText = FilText & "Text Files" Else _ FilText = FilText & ";Text Files" If FilTypes = "" Then FilTypes = "*.txt" Else _ FilTypes = FilTypes & ";*.txt" End If If FilTypes = "" Then FilText = "All Files" If FilTypes = "" Then FilTypes = "*.*" FilText = FilText & "," & FilTypes GetFile = AppXL.GetOpenFilename(FilText, , Heading, False) AppXL.Quit Set AppXL = Nothing End Function -- - K Dales "MDW" wrote: Hello. I'd like to create a UI where my users can graphically navigate through folder lists and select files. I don't want to programmatically invoke the Windows Explorer unless there's a way to embed it on a Userform (I don't want it in a seperate window). I looked at the TreeView control, and it looks like it will satisfy at least the folder browsing part, but I seem to recall that there's a control somewhere that's already set up to display folders in a similar fashion. I can't for the life of me remember what it is, though. And advice/pointers would be appreciated. I don't want to reinvent the wheel using a TreeView if there's another option. Thanks. -- Hmm...they have the Internet on COMPUTERS now! |
Embed Folder Treeview Or Windows Explorer On UserForm
I...don't think this is what I need.
What I'm looking for is an object, with properties and methods, that replicates to some degree the treeview on the Windows Explorer. I don't want the user to have to pick from dialog boxes. I know could use a TreeView control and populate it via the FileSystem object, but it seems to me like there's already a control that's designed explicitly for directory browsing. I just can't seem to find it. Thanks though. -- Hmm...they have the Internet on COMPUTERS now! "K Dales" wrote: the GetOpenFileName Method is, I think, what you are thinking of. Here is a function I wrote for selecting a file ( I wrote it to be run from Access, so it creates an Excel object; you can skip that if you are running it in Excel): Public Function GetFile(Types As Byte, Optional FPath As String, Optional Prompt As String) As String ' Function to open file selection dialog box, return selected file path and name ' NOTE: Must include reference to the Microsoft Excel Object Library to use its ' File dialog box as an object ' ' Types will have bits set according to the types of files being searched for: ' (note: these were set by me, can be modified or extended) ' 00000001 (AllFiles,&H1) All Files ' 00000010 (TextFiles,&H2) for Text Files,*.txt ' 00000100 (PLMFiles,&H4) for PLM download files,*.rpt ' 00001000 (CSVFiles,&H8) for Comma Separated Values,*.csv ' 00010000 (ExcelFiles,&H10) for Excel Files,*.xls ' 00100000 (AccessFiles,&H20) for Access Files,*.mdb ' 01000000 (&H40) RESERVED ' 10000000 (&H80) RESERVED ' Any other choice, e.g. Types = 0, will give "All Files" ' User can "OR" these choices to get multiple file types ' FPath is the default file path ' Header is what will appear as the dialog box title ' Must declare an object variable as an Excel Application to allow the use of ' the Excel file selection dialog ' (ONLY if not run in Excel, just use Application object if you are already in Excel) Dim AppXL As New Excel.Application Dim FilText, FilTypes As String Dim Heading As Variant AppXL.DefaultFilePath = FPath If Prompt = "" Then Heading = "SELECT FILE" Else Heading = Prompt FilText = "" FilTypes = "" ' Set the FileFilter based on the Types specified If ((Types And &H20) = &H20) Then FilText = "ACCESS" If ((Types And &H20) = &H20) Then FilTypes = "*.mdb" If ((Types And &H10) = &H10) Then If FilText = "" Then FilText = FilText & "EXCEL" Else _ FilText = FilText & ";EXCEL" If FilTypes = "" Then FilTypes = "*.xls" Else _ FilTypes = FilTypes & ";*.xls" End If If ((Types And &H8) = &H8) Then If FilText = "" Then FilText = FilText & "Comma-Separated Values" Else _ FilText = FilText & ";Comma-Separated Values" If FilTypes = "" Then FilTypes = "*.csv" Else _ FilTypes = FilTypes & ";*.csv" End If If ((Types And &H4) = &H4) Then If FilText = "" Then FilText = FilText & "PLM Download Files" Else _ FilText = FilText & ";PLM Download Files" If FilTypes = "" Then FilTypes = "*.rpt" Else _ FilTypes = FilTypes & ";*.rpt" End If If ((Types And &H2) = &H2) Then If FilText = "" Then FilText = FilText & "Text Files" Else _ FilText = FilText & ";Text Files" If FilTypes = "" Then FilTypes = "*.txt" Else _ FilTypes = FilTypes & ";*.txt" End If If FilTypes = "" Then FilText = "All Files" If FilTypes = "" Then FilTypes = "*.*" FilText = FilText & "," & FilTypes GetFile = AppXL.GetOpenFilename(FilText, , Heading, False) AppXL.Quit Set AppXL = Nothing End Function -- - K Dales "MDW" wrote: Hello. I'd like to create a UI where my users can graphically navigate through folder lists and select files. I don't want to programmatically invoke the Windows Explorer unless there's a way to embed it on a Userform (I don't want it in a seperate window). I looked at the TreeView control, and it looks like it will satisfy at least the folder browsing part, but I seem to recall that there's a control somewhere that's already set up to display folders in a similar fashion. I can't for the life of me remember what it is, though. And advice/pointers would be appreciated. I don't want to reinvent the wheel using a TreeView if there's another option. Thanks. -- Hmm...they have the Internet on COMPUTERS now! |
Embed Folder Treeview Or Windows Explorer On UserForm
application.getopenfilename()
seems like it should work. You can even use multiselect:=true to get more than one filename in that same folder. Option Explicit Sub testme01() Dim myFileNames As Variant Dim wkbk As Workbook Dim fCtr As Long myFileNames = Application.GetOpenFilename("Excel Files, *.xls", _ MultiSelect:=True) If IsArray(myFileNames) = False Then Exit Sub End If For fCtr = LBound(myFileNames) To UBound(myFileNames) Set wkbk = Workbooks.Open(FileName:=myFileNames(fCtr)) 'do some things wkbk.Close savechanges:=True 'or False??? Next fCtr End Sub ============ If you're looking for a name to save a file, look at Application.GetSaveAsFilename in VBA's help. MDW wrote: Hello. I'd like to create a UI where my users can graphically navigate through folder lists and select files. I don't want to programmatically invoke the Windows Explorer unless there's a way to embed it on a Userform (I don't want it in a seperate window). I looked at the TreeView control, and it looks like it will satisfy at least the folder browsing part, but I seem to recall that there's a control somewhere that's already set up to display folders in a similar fashion. I can't for the life of me remember what it is, though. And advice/pointers would be appreciated. I don't want to reinvent the wheel using a TreeView if there's another option. Thanks. -- Hmm...they have the Internet on COMPUTERS now! -- Dave Peterson |
Embed Folder Treeview Or Windows Explorer On UserForm
If that is so I don't know of any ActiveX control that is supplied with
Office that does what you want, perhaps a 3rd party control exists. Otherwise you are correct that you could do it with a treeview but it would take a while to do all the coding. Perhaps someone else out there knows a control that does this. -- - K Dales "MDW" wrote: I...don't think this is what I need. What I'm looking for is an object, with properties and methods, that replicates to some degree the treeview on the Windows Explorer. I don't want the user to have to pick from dialog boxes. I know could use a TreeView control and populate it via the FileSystem object, but it seems to me like there's already a control that's designed explicitly for directory browsing. I just can't seem to find it. Thanks though. -- Hmm...they have the Internet on COMPUTERS now! "K Dales" wrote: the GetOpenFileName Method is, I think, what you are thinking of. Here is a function I wrote for selecting a file ( I wrote it to be run from Access, so it creates an Excel object; you can skip that if you are running it in Excel): Public Function GetFile(Types As Byte, Optional FPath As String, Optional Prompt As String) As String ' Function to open file selection dialog box, return selected file path and name ' NOTE: Must include reference to the Microsoft Excel Object Library to use its ' File dialog box as an object ' ' Types will have bits set according to the types of files being searched for: ' (note: these were set by me, can be modified or extended) ' 00000001 (AllFiles,&H1) All Files ' 00000010 (TextFiles,&H2) for Text Files,*.txt ' 00000100 (PLMFiles,&H4) for PLM download files,*.rpt ' 00001000 (CSVFiles,&H8) for Comma Separated Values,*.csv ' 00010000 (ExcelFiles,&H10) for Excel Files,*.xls ' 00100000 (AccessFiles,&H20) for Access Files,*.mdb ' 01000000 (&H40) RESERVED ' 10000000 (&H80) RESERVED ' Any other choice, e.g. Types = 0, will give "All Files" ' User can "OR" these choices to get multiple file types ' FPath is the default file path ' Header is what will appear as the dialog box title ' Must declare an object variable as an Excel Application to allow the use of ' the Excel file selection dialog ' (ONLY if not run in Excel, just use Application object if you are already in Excel) Dim AppXL As New Excel.Application Dim FilText, FilTypes As String Dim Heading As Variant AppXL.DefaultFilePath = FPath If Prompt = "" Then Heading = "SELECT FILE" Else Heading = Prompt FilText = "" FilTypes = "" ' Set the FileFilter based on the Types specified If ((Types And &H20) = &H20) Then FilText = "ACCESS" If ((Types And &H20) = &H20) Then FilTypes = "*.mdb" If ((Types And &H10) = &H10) Then If FilText = "" Then FilText = FilText & "EXCEL" Else _ FilText = FilText & ";EXCEL" If FilTypes = "" Then FilTypes = "*.xls" Else _ FilTypes = FilTypes & ";*.xls" End If If ((Types And &H8) = &H8) Then If FilText = "" Then FilText = FilText & "Comma-Separated Values" Else _ FilText = FilText & ";Comma-Separated Values" If FilTypes = "" Then FilTypes = "*.csv" Else _ FilTypes = FilTypes & ";*.csv" End If If ((Types And &H4) = &H4) Then If FilText = "" Then FilText = FilText & "PLM Download Files" Else _ FilText = FilText & ";PLM Download Files" If FilTypes = "" Then FilTypes = "*.rpt" Else _ FilTypes = FilTypes & ";*.rpt" End If If ((Types And &H2) = &H2) Then If FilText = "" Then FilText = FilText & "Text Files" Else _ FilText = FilText & ";Text Files" If FilTypes = "" Then FilTypes = "*.txt" Else _ FilTypes = FilTypes & ";*.txt" End If If FilTypes = "" Then FilText = "All Files" If FilTypes = "" Then FilTypes = "*.*" FilText = FilText & "," & FilTypes GetFile = AppXL.GetOpenFilename(FilText, , Heading, False) AppXL.Quit Set AppXL = Nothing End Function -- - K Dales "MDW" wrote: Hello. I'd like to create a UI where my users can graphically navigate through folder lists and select files. I don't want to programmatically invoke the Windows Explorer unless there's a way to embed it on a Userform (I don't want it in a seperate window). I looked at the TreeView control, and it looks like it will satisfy at least the folder browsing part, but I seem to recall that there's a control somewhere that's already set up to display folders in a similar fashion. I can't for the life of me remember what it is, though. And advice/pointers would be appreciated. I don't want to reinvent the wheel using a TreeView if there's another option. Thanks. -- Hmm...they have the Internet on COMPUTERS now! |
All times are GMT +1. The time now is 12:30 AM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com