Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Westi on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need 2 import *.txt -> XL as pure text - Help w/OpenText ??

Status
Not open for further replies.

JetBlack

Technical User
Jun 12, 2003
2
US
I have some fairly long macros designed to handle production of some HTML files, using some csv files I get regularly from a client. Trouble is, I can only seem to get Excel to manage everything properly if I open the files as PURE TEXT ... meaning I have to rename the csv as txt, and then step through the entire "Text Import Wizard" to open the file properly. (It is the LAST section of the wizard, where I have to select ALL of the columns of data and specify them to be opened as "text" which seems to be the critical part.)

I want to add a bit of code to my macro so that I can automate what the text import wizard does (why aren't there just some "file open tags" or parameters I can use to force the file to open this way?) but I keep running into problems. When I try to use the recorder, it always hiccups with a "too many line continuations" error.

I assume I can probably solve this problem with the OpenText method, but can't find a good example/tutorial.

Any help?

THX!
 
Did you look into using a scripting object.
ex.

Set filesys = CreateObject("Scripting.FileSystemObject")
Set filetxt = filesys.OpenTextFile("File Path", 1)

[Returns First Line Of file] = filetxt.ReadLine

filetxt.Close

 
Guys:

Thanks for the suggestions!

I ended up finding a workaround WITHOUT using the OpenText method. Apparently there is some deficiency (bug?) in Excel 97 where if a text file has more than 99 columns, it "freaks out" the import feature when using a MACRO.

Somewhere (I don't even remember where ... might have been Microsoft, or another forum) I saw a workaround using a nested array to "fool" it into allowing more than 99 columns. Works like a charm!

If this is something anyone would like to see, let me know and I'll post the code.

THANKS AGAIN!

- Jet
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top