-----Original Message-----
The following code in the initialize event of a userform will load a listbox
with the documents contained in a folder that the user selects. In your
case, it will be more appropriate to hardcode the path to the folder and not
give the user the choice.
Dim MyPath As String
Dim MyName As String
'let user select a path
With Dialogs(wdDialogCopyFile)
If .Display() <> -1 Then Exit Sub
MyPath = .Directory
End With
'strip quotation marks from path
If Len(MyPath) = 0 Then Exit Sub
If Asc(MyPath) = 34 Then
MyPath = Mid$(MyPath, 2, Len(MyPath) - 2)
End If
'get files from the selected path
'and insert into the listbox
MyName = Dir$(MyPath & "*.*")
Do While MyName <> ""
ListBox1.AddItem MyName
MyName = Dir
Loop
--
Please respond to the Newsgroup for the benefit of others who may be
interested. Questions sent directly to me will only be answered on a paid
consulting basis.
Hope this helps,
Doug Robbins - Word MVP
.
=============================================
Ok thanks for all the help I have my listbox populated
with the directory I want. I just have to now make it work
so if the user selects the 1 2 or 10th file it will open
the file with the correct application and hid the form.
Any help appreciated here is what I have so far
******* straight from the site ******
Private Sub UserForm_Initialize()
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:\temp\*.*")
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)
LisBox1.list = DirectoryListArray