Importing text files using macro

G

Guest

Hello:
I have recorded a macro in Excel that imports a text file into Excel - so
Data > Get External Data > Import Text File and then follow the wizard. How
can I import another file using the same macro without having to go over the
same steps..i.e using the wizard, etc.
Thanks,
Jade.
 
G

Gary Keramidas

can you answer a few questions?

are the filenames always going to be the same?
are they going to be imported to the same sheet, or do you want them on separate
sheets?
i'm guessing the format of the text file is the same.

just change the name of file in the macro you recorded to the new name, if you
just want it on the same sheet

here is some code to get rid of the query if you don't ever want to update the
data

Sub Remove_Query()
For Each sheet In Sheets
i = sheet.Index
For j = Worksheets(i).QueryTables.Count To 1 Step -1
Set MyQT = Worksheets(i).QueryTables(j)
MyQT.Delete
Next
Next
End Sub
 
G

Guest

Thanks Gary.
The file names are always going to be different and I want them imported to
the same sheet and sometimes to different sheets.
There are 2 different files text files. One has 16 columns and the other 7.
Multiple files of both kinds will be saved and I just want to use the same
macro to open them in Excel instead of always having to record a macro or go
through the wizard to import each one.
Thanks,
J
 

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