ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   how to return a file name (https://www.excelbanter.com/excel-programming/386542-how-return-file-name.html)

Monte0682

how to return a file name
 
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...


Dave Peterson

how to return a file name
 
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.


Monte0682 wrote:

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


--

Dave Peterson

Bob Flanagan

how to return a file name
 
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

"Monte0682" wrote in message
ups.com...
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...




Monte0682

how to return a file name
 
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...



All times are GMT +1. The time now is 01:16 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
ExcelBanter.com