![]() |
Excel VBA-Importing txt files with VBA
Several options he
Chip Pearson has sample code for importing (and exporting) as CSV type file with a user specified delimiter: http://www.cpearson.com/excel/imptext.htm import/export text files you can turn on the macro recorder and open the file in Excel - going through the text improt wizard specifying the appropriate settings. This will be recorded as a single instance of the OpenText method with the selections you made recorded as arguments to that method. If you then run this macro, it will open the file using those settings (it won't show the wizard). one argument is Filename:= You can replace the hard coded file name produced by the recorder with a variable and populate that variable using fName = GetOpenFilename See help for arguments to getopenfilename. This shows the file=Open dialog and returns your selection to the variable fname as shown in the example. It does not open the file. You could then use the value in Fname as the argument to OpenText. You can also write low level file IO if you wish: http://support.microsoft.com/support...eio/fileio.asp File Access with Visual Basic® for Applications This gives you maximum flexibility, but requires you to do most of the work in writing the code. -- Regards, Tom Ogilvy "pwdiaz " wrote in message ... Hi All! I need to write a procedure that will import txt files into Excel. The procedure, when called upon, must allow the user to select the text file. These txt files contain data from instruments such as spectrophotometers, luminometers etc and are typically written in row and column formats using various delimiters depending on the machine that generated them. Some txt file outputs are in tab deliminted format others are in csv etc. Generally the data is in either an 8x12 or 16x24 matrix or array if you prefer, representing the format of the original microplate from which the data are derived. All I need is a tip or example code that will allow the automated import of the selected text file with each element of the matrix or array to appear in discrete cells of the work sheet. I am by necesssity working directly with text files rather than a database so hopefully someone has a solution that can do the import directly from the text file. Thanks! Paul --- Message posted from http://www.ExcelForum.com/ |
All times are GMT +1. The time now is 05:16 PM. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
ExcelBanter.com