PDA

View Full Version : [SOLVED:] loop through all selected items in dialog



saban
11-09-2007, 01:25 AM
Private Sub CommandButton1_Click()
Dim fd As FileDialog
Dim luka As Variant
Set fd = Application.FileDialog(msoFileDialogFilePicker)
Dim vrtSelectedItem As Variant
With fd
If .Show = -1 Then
For Each vrtSelectedItem In .SelectedItems
' MsgBox "The path is: " & vrtSelectedItem
'Set files = luka
FileMask_Box = vrtSelectedItem
' files = Application.FileDialog(msoFileDialogOpen).SelectedItems
Next
End If
FileMask_Box.Enabled = False
End With
End Sub

How can I do this:

I will select multiple files (but how do I store all of them in some array) and put them public so when next sub is invoked it does something like:
In Private Sub CommandButton2_Click() I need those values:
fileName = files from CommandButton1_Click
Selectedfiles = files from CommandButton1_Click

So I can do this:
For Each fileName In Selectedfiles

TonyJollans
11-09-2007, 02:30 AM
Easiest way is probably to make the Dialog public ..



Dim fd As FileDialog
Dim rc



Private Sub CommandButton1_Click()
Set fd = Application.FileDialog(msoFileDialogFilePicker)
rc = fd.Show
End Sub

Private Sub Another Routine()
Dim luka As Variant
Dim vrtSelectedItem As Variant
With fd
If rc -1 Then
For Each vrtSelectedItem In .SelectedItems
' Do whatever you want here
' MsgBox "The path is: " & vrtSelectedItem
'Set files = luka
FileMask_Box = vrtSelectedItem
' files = Application.FileDialog(msoFileDialogOpen).SelectedItems
Next
End If
FileMask_Box.Enabled = False
End With
End Sub