ExcelBanter

ExcelBanter (https://www.excelbanter.com/)
-   Excel Programming (https://www.excelbanter.com/excel-programming/)
-   -   Importing text files using macro (https://www.excelbanter.com/excel-programming/373372-importing-text-files-using-macro.html)

Jade5

Importing text files using macro
 
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.

Gary Keramidas

Importing text files using macro
 
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

--


Gary


"Jade5" wrote in message
...
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.




Jade5

Importing text files using macro
 
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
"Gary Keramidas" wrote:

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

--


Gary


"Jade5" wrote in message
...
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.






All times are GMT +1. The time now is 10:24 AM.

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