Hi All pretty self explanetry im trying to write some code (for outlook but should be the same) using a userform to show a list of folders then opens the selected folder but ive got a mind blank anyone that can help would be epic!!!
Hi All pretty self explanetry im trying to write some code (for outlook but should be the same) using a userform to show a list of folders then opens the selected folder but ive got a mind blank anyone that can help would be epic!!!
Maybe:
![]()
Option Explicit Private Const strBasePath As String = "C:\Users\Public\" Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean) Shell "explorer.exe " & Me.ListBox1.value, vbNormalFocus End Sub Private Sub UserForm_Initialize() Dim objFSO As Object Dim objFolderCollection As Object Dim objFolder As Object Dim varFolders As Variant Dim lngCounter As Long Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFolderCollection = objFSO.getfolder(strBasePath).subfolders ReDim varFolders(0 To objFolderCollection.Count - 1, 0 To 1) For Each objFolder In objFolderCollection varFolders(lngCounter, 0) = objFolder.Path varFolders(lngCounter, 1) = objFolder.Name lngCounter = lngCounter + 1 Next objFolder With Me.ListBox1 .ColumnCount = 2 .ColumnWidths = "0,100" .List = varFolders End With End Sub
my good friend you are a legend you have no idea how long ive been searching for a solution to this!!!! for time saving if i wanted say 4 different list boxes on the same input form would i just change all the "listbox1" parts to 2 ext and the file path? if not its no problem thanks in advance
Edit: and the "Strbasepath" to a 2 3 ect
Last edited by Kezwick; 08-08-2013 at 05:04 AM.
Thanks for the feedback, glad it helped. Are you wanting all the listboxes to display the same list of files or different ones?
Maybe:
![]()
Option Explicit Private objFSO As Object Private Sub ListBox1_DblClick(ByVal Cancel As MSForms.ReturnBoolean) Shell "explorer.exe " & Me.ListBox1.value, vbNormalFocus End Sub Private Sub ListBox2_DblClick(ByVal Cancel As MSForms.ReturnBoolean) Shell "explorer.exe " & Me.ListBox2.value, vbNormalFocus End Sub Private Sub ListBox3_DblClick(ByVal Cancel As MSForms.ReturnBoolean) Shell "explorer.exe " & Me.ListBox3.value, vbNormalFocus End Sub Private Sub UserForm_Initialize() Dim objControl As MSForms.Control For Each objControl In Me.Controls If TypeOf objControl Is MSForms.ListBox Then With objControl .ColumnCount = 2 .ColumnWidths = "0,100" End With End If Next objControl Me.ListBox1.List = GetFolderList("C:\Users\Public\") Me.ListBox2.List = GetFolderList("C:\Some Folder\") Me.ListBox3.List = GetFolderList("C:\Some other Folder\") End Sub Private Function GetFolderList(strPath As String) As Variant Dim objFSO As Object Dim objFolderCollection As Object Dim objFolder As Object Dim varFolders As Variant Dim lngCounter As Long If objFSO Is Nothing Then Set objFSO = CreateObject("Scripting.FileSystemObject") Set objFolderCollection = objFSO.getfolder(strPath).subfolders ReDim varFolders(0 To objFolderCollection.Count - 1, 0 To 1) For Each objFolder In objFolderCollection varFolders(lngCounter, 0) = objFolder.Path varFolders(lngCounter, 1) = objFolder.Name lngCounter = lngCounter + 1 Next objFolder GetFolderList = varFolders End Function
Last edited by Kyle123; 08-08-2013 at 06:29 AM.
its no bigy just me bing lazy realy haha the solution you provided was brill so i jsut coppied it over 3 userforms and it works a dream!! many thanks again
There are currently 1 users browsing this thread. (0 members and 1 guests)
Bookmarks