how to return a file name

  • Thread starter Thread starter Monte0682
  • Start date Start date
M

Monte0682

I would like to import a text file and then reurn its file name into a
text box. I have used this:

Application.Dialogs(xlDialogImportTextFile).Show

to open a box to import a file...
 
I think I'd use something like:

Dim myFileName as variant
myfilename = application.getopenfilename("Text files, *.xls")
if myfilename = false then
exit sub '??? user hit cancel
end if

msgbox myfilename

And if the layout of the input file never changes (always comma delimited or
same fixed width layout), the next step would be to open the file using those
rules:

Workbooks.OpenText Filename:=myFileName, _
StartRow:=1, DataType:=xlDelimited, TextQualifier:=xlDoubleQuote, _
....

I'd record a macro to get the exact details for that .opentext statement.
 
If the file has been opened and is the active workbook, then
ActiveWorkbook.Name returns its name.

If you have a userform where you want to enter that name, then this would
set the text box on the form to the name:

Userform1.Textbox1.Text = Activeworkbook.name

Bob Flanagan
Macro Systems
http://www.add-ins.com
Productivity add-ins and downloadable books on VB macros for Excel
 
hello,

my question was:

I have a workbook. I would like to import a text file into one of the
worksheets...When I go Data, get external data, import text file... To
do this I use Application.Dialogs(xlDialogImportTextFile).Show

This will import a file, ask for a delimiter...

But I would like to export a file name that a opened for later
reference... Also I would like to specify into which worksheet I would
like to import...
 

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

Back
Top