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
Jezebel - 06 Mar 2007 00:06 GMT
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
>I have a macro that prompts me to enter a file name and then it gets the
>text
[quoted text clipped - 13 lines]
> End If
> Open tempfile For Input As #1
Jay Freedman - 06 Mar 2007 02:27 GMT
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 FAQ: http://word.mvps.org
Email cannot be acknowledged; please post all follow-ups to the
newsgroup so all may benefit.
>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
[quoted text clipped - 23 lines]
>> End If
>> Open tempfile For Input As #1
LEU - 06 Mar 2007 20:49 GMT
I like how this works. How do I add to it to tell it to alway go to
"C:\History\"
> 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
[quoted text clipped - 23 lines]
> > End If
> > Open tempfile For Input As #1
LEU - 06 Mar 2007 21:05 GMT
I figured it out. I just added the following:
ChangeFileOpenDirectory "C:\History\"
Thanks again for all your help.
> I like how this works. How do I add to it to tell it to alway go to
> "C:\History\"
[quoted text clipped - 26 lines]
> > > End If
> > > Open tempfile For Input As #1
LEU - 06 Mar 2007 22:54 GMT
How do I make the the only file option to copy or save a ".txt" file?
> 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
[quoted text clipped - 10 lines]
> End If
> Open tempfile For Input As #1