form with list of documents

B

bbry

I have a shared folder with 30 documents in the folder
that I want users to use. These documents are templates
that I want people to fill in at different times.
I have created a form with a listbox. I would like to be
able to have all the document names in the listbox and
when the user fines the one they want just click on it and
hit enter to be brought to that document. Can someone help
me with this

THanks
 
D

Doug Robbins

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
 
B

bbry

-----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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top