Discussion Locked

auto import into excel

0 helpful
10 replies
Closed to new repliesThis discussion is closed. It stays readable, but it takes no new replies.
I am trying to figure out how to write a script that will import a text file into excel when run. Is there a way to do this at with a .bat file? I have a text file that imports directly into excel manually with no changes, just by clicking next/finish until done. Thanks for any suggestions!

10 replies

by dklippert

Go to Tools>Macro Record New Macro.
Run through the import. Then turn off the recorder.
You can now run the macro to reproduce your actions.
If you name the macro AutoOpen, it will run when you open Excel.

by seadogs

I followed answer one and can run the macro. However it does not run when I open excel or when I open the particular spreadsheet I made it in. I have to specifically run it. Also I'd like for this information to be run by a scipt if at all possible so that it can be updated when I access it. Basically there's a program that gets some information that I run on the command line, then puts it into a text file, and I'd like to be able to have that text file imported into excel automatically. Thanks!

by kees.valkenswaard

When going back to Stone Age, it is a simple task. Just add
excel.exe MYBOOK
in your batch file and that it is.
However, it is probably a nightmare to find out all the paths in shorthand with the ~ in it. You may have to give the exact path for both Excel and your Excel Workbook. The Excel file MYBOOK should contain the AutoOpen macro.
Depending on your system set-up it may or may not be required to add .xls to MYBOOK. [Obviously any name is OK] Actually I don?t remember exactly how to write it. However, I have used this possibility quite often in the past, by opening several Office programs this way. [on my current system the .xls would not be required]
You also may use a template rather than a workbook.
What I did more recently were Excel files in which I could choose which text file [in a given directory and perhaps with given characteristics, such as a few fixed characters, the remainder by wild cards] to import. This as each day a new text file was created and I till wanted to be able to run older files. The AutoOpen macro would show a form with a list box showing all the filenames satisfying m requirements.
Good luck.

This discussion is closed to new replies.