K
Kerry Hewett
Hi
I have created a user form to display the contents of a
folder in a list box - this is working wonderfully (please
see code below).
What I now need to do is allow the user to double click
many of these files copying them into another list box.
The users will then re-arrange the files in the 2nd list
box to choose what order to insert them into the current
document.
Is this possible?? Can anyone please help or suggest a
good place/book to start.
Thanks very much for your time.
CODE:
Private Sub UserForm_Activate()
Dim MyFile As String
Dim Counter As Long
'Create a dynamic array variable, and then declare its
initial size
Dim DirectoryListArray() As String
ReDim DirectoryListArray(1000)
'Loop through all the files in the directory by using Dir$
function
MyFile = Dir$("C:\my Documents\*.*")
Do While MyFile <> ""
DirectoryListArray(Counter) = MyFile
MyFile = Dir$
Counter = Counter + 1
Loop
'Reset the size of the array without losing its values by
using Redim Preserve
ReDim Preserve DirectoryListArray(Counter - 1)
'To prove it worked you could run the following:
For Counter = 0 To UBound(DirectoryListArray)
'Debug.Print writes the results to the Immediate
window (press Ctrl + G to view it)'
Debug.Print DirectoryListArray(Counter)
Next Counter
'To populate a Listbox from the array you could use:
ListBox1.List = DirectoryListArray
End Sub
I have created a user form to display the contents of a
folder in a list box - this is working wonderfully (please
see code below).
What I now need to do is allow the user to double click
many of these files copying them into another list box.
The users will then re-arrange the files in the 2nd list
box to choose what order to insert them into the current
document.
Is this possible?? Can anyone please help or suggest a
good place/book to start.
Thanks very much for your time.
CODE:
Private Sub UserForm_Activate()
Dim MyFile As String
Dim Counter As Long
'Create a dynamic array variable, and then declare its
initial size
Dim DirectoryListArray() As String
ReDim DirectoryListArray(1000)
'Loop through all the files in the directory by using Dir$
function
MyFile = Dir$("C:\my Documents\*.*")
Do While MyFile <> ""
DirectoryListArray(Counter) = MyFile
MyFile = Dir$
Counter = Counter + 1
Loop
'Reset the size of the array without losing its values by
using Redim Preserve
ReDim Preserve DirectoryListArray(Counter - 1)
'To prove it worked you could run the following:
For Counter = 0 To UBound(DirectoryListArray)
'Debug.Print writes the results to the Immediate
window (press Ctrl + G to view it)'
Debug.Print DirectoryListArray(Counter)
Next Counter
'To populate a Listbox from the array you could use:
ListBox1.List = DirectoryListArray
End Sub