Display file list

L

LEU

I have a macro that prompts me to enter a file name and then it gets the text
and writes it to my document. I have too many file names now to remember them
all. Is there a way to display all the files in my folder and I can just
choose the one I want? Here is the first part of my macro that gets the file:

Dim tempfile
Dim bk1, bk2, bk3, bk4, bk5, bk6, bk7
tempfile = InputBox("Input your file name")
tempfile = "C:\History\†+ tempfile + ".txt"
If Dir(tempfile) = "" Then
MsgBox "This file doesn't exist please try again", , "No File"
Exit Sub
End If
Open tempfile For Input As #1
 
J

Jezebel

Why not use the File > Open dialog? If you Display the dialog (instead of
using Show) Word takes no action when the user clicks OK -- it simply
returns whatever filename the user selected --

With Dialogs(wdDialogFileOpen)
If .Display = -1 then
Tempfile = .Name
End if
End with
 
J

Jay Freedman

Or, if all the macro has to do is insert the file's text at the
cursor, just use the Insert > File command, which displays a dialog
similar to the File > Open dialog and does all the rest of the work
for you -- no macro necessary.

--
Regards,
Jay Freedman
Microsoft Word MVP
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
 
L

LEU

I figured it out. I just added the following:

ChangeFileOpenDirectory "C:\History\"

Thanks again for all your help.
 

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