PDA

View Full Version : How can I put Multiselected files (not one) into listbox?



jiura
04-24-2008, 10:01 AM
Hello I have a program in witch user with common dialog control could select many files. When he clicks on Botton Open program must opy this files with path's to list box. But I can't do this beciuse I don't understand how to copy all this parths to listbox.


To allow user to open many files I write:

Frmt.CommonDialog1.Flags = 1048576
Frmt.CommonDialog1.ShowOpen

Oorang
04-24-2008, 11:38 AM
Option Explicit
' To use this code:
' 1.) Set a reference to the Microsoft Scripting Runtime
' 2.) Create userform with one listbox named "ListBox1"
' 3.) Paste this code into userform and open/run form.

Private Sub UserForm_Initialize()
Dim fso As Scripting.FileSystemObject
Dim strFldr As String
Dim fldr As Scripting.Folder
Dim fl As Scripting.File
Dim lngIndx As Long
Dim varList() As Variant
strFldr = GetFolder
PrepForm
Set fso = New Scripting.FileSystemObject
Set fldr = fso.GetFolder(strFldr)
ReDim varList(fldr.Files.Count, 1)
For Each fl In fldr.Files
varList(lngIndx, 0) = fl.Name
varList(lngIndx, 1) = strFldr
lngIndx = lngIndx + 1
Next
Me.ListBox1.List = varList
End Sub

Private Function GetFolder() As String
Dim fd As Office.FileDialog
Set fd = Excel.Application.FileDialog(msoFileDialogFolderPicker)
If fd.Show Then
GetFolder = fd.SelectedItems(1)
End If
End Function

Private Sub PrepForm()
With Me
.Height = 410
.Width = 405
End With
With Me.ListBox1
.Left = 5
.Top = 5
.Width = 390
.Height = 380
.ColumnCount = 2
.ColumnWidths = "160;220"
.ListStyle = fmListStylePlain
.MultiSelect = fmMultiSelectSingle
End With
End Sub

jiura
04-24-2008, 12:44 PM
Thanks!

Bob Phillips
04-24-2008, 12:46 PM
' To use this code:
' 1.) Set a reference to the Microsoft Scripting Runtime <<<<<<<<<<<<<
' 2.) Create userform with one listbox named "ListBox1"
' 3.) Paste this code into userform and open/run form.