Computing.Net > Forums > Office Software > Importing text file to EXCEL

Computer Problems? Computing.Net has over 1,000,000 posts about all things technology related! Over 90% answered within 24 hours! Click here to start participating now! Also, be sure to check out the New User Guide.

Importing text file to EXCEL

Reply to Message Icon

Name: raoshri
Date: February 3, 2005 at 07:23:31 Pacific
OS: XP
CPU/Ram: Intel P4 256 MB RAM
Comment:

Hello,

I am importing text files(downloaded from the mainframe) to excel, and every time I am using the same copybook layout.

These are text files without any delimiters and am using the fixed width option.

Is there any way I can use this layout to just superimpose new text files on the excel sheet, without having to go thru the process all over again??

Any help would be appreciated.

Thx
Shrikant




Sponsored Link
Ads by Google

Response Number 1
Name: Bryco
Date: February 3, 2005 at 16:54:41 Pacific
Reply:

You can...sort of.

Using VBA (Macro)

Go to Excel Tools, Macro, Record new macro.
Go to File, Open, browse to one of these files and open it.

Make all of your settings as you normally would to format one of these files.

After clicking the Finish button click on the Stop recording button.

Now the good part...
Open a new blank workbook.
Switch back to the first one.
Hit Alt+F11 to open the VBA editor.
Go to Edit, Select all, Edit Copy.
Close the first workbook (Save it if you like or not).

In the new workbook and hit Alt+F11.
Go to Insert, New Module.
Go to Edit, Paste.

Save the New workbook as OpenFile.xls to somewhere easy to get to like My Documents.

Now hit Alt+F11 to open the VBA editor if it is not still open.

The first line of the macro's code will look very much like:
Workbooks.OpenText FileName:="C:\My Documents\yourfile.txt", _
(all in one line of course)
Highlight it and delete it.

Now Copy and Paste the following in it's place for the first two lines of code:
myFile = Application.GetOpenFilename("Text Files,*.txt")
Workbooks.OpenText Filename:=myFile, _

Save it.

The replacement code makes the Open File dialog box appear so you can select the correct .txt file to open and then run your formatting code upon.

The next time you want to format one of the mentioned files open the "OpenFile.xls" workbook first so the macro will be available to any open workbook.
Then open a New workbook, go to Tools, Macro, Macros... and select it from the list (that only contains one anyway), browse to the .txt file and select it.

HTH
Bryan


0
Reply to Message Icon

Related Posts

See More







Post Locked

This post is quite old and has been locked from receiving new replies. Please create a new posting instead.


Go to Office Software Forum Home


Sponsored links

Ads by Google


Results for: Importing text file to EXCEL

macro code to import text file to excel 2003 www.computing.net/answers/office/macro-code-to-import-text-file-to-excel-2003/8815.html

Text file to Access help www.computing.net/answers/office/text-file-to-access-help/499.html

HOW2 Import Txt File to end COLUMNS www.computing.net/answers/office/how2-import-txt-file-to-end-columns/3817.html