Consulting

Results 1 to 4 of 4

Thread: How can I put Multiselected files (not one) into listbox?

  1. #1

    How can I put Multiselected files (not one) into listbox?

    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:
    [VBA]
    Frmt.CommonDialog1.Flags = 1048576
    Frmt.CommonDialog1.ShowOpen
    [/VBA]

  2. #2
    Knowledge Base Approver VBAX Master Oorang's Avatar
    Joined
    Jan 2007
    Posts
    1,135
    Location
    [VBA]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
    [/VBA]
    Cordially,
    Aaron



    Keep Our Board Clean!
    • Please Mark your thread "Solved" if you get an acceptable response (under thread tools).
    • Enclose your code in VBA tags then it will be formatted as per the VBIDE to improve readability.

  3. #3
    Thanks!

  4. #4
    Distinguished Lord of VBAX VBAX Grand Master Bob Phillips's Avatar
    Joined
    Apr 2005
    Posts
    25,443
    Location
    [vba]
    ' 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.
    [/vba]
    ____________________________________________
    Nihil simul inventum est et perfectum

    Abusus non tollit usum

    Last night I dreamed of a small consolation enjoyed only by the blind: Nobody knows the trouble I've not seen!
    James Thurber

Posting Permissions

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