Tom's Guide | Tom's Hardware | Tom's Games
![]() |
![]() |
![]() |
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

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

![]() |
![]() |
![]() |

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