Trouble reading in txt file. Only want to read in certain columns.


Posted by Edward Clutter on February 15, 2001 1:48 PM

Hi Everyone,
I need to be able to read in 1 to 5 very large data files that are stored as *.txt files. I used the record macro feature to make the following macro. I basically used the open feature and deactivated all of the columns except the two I wanted. It works when I do it manually, but when I try to play back the macro, I get an "out of memory message". Anyone know why that is, and does anyone know of a better way to do what I want?
Thanks
Edward
Macro: (see listing below)

Sub read_in_data_file()
'
' read_in_data_file Macro
' Macro recorded 1/26/01 by clutter
'

'
Sheets("Sheet2").Select
ChDir "D:\Edward\Mercury_data_processing_010801\data\PPBreadboard\000911"
Workbooks.OpenText FileName:= _
"D:\Edward\Mercury_data_processing_010801\data\PPBreadboard\000911\MercuryBreadBBoard_20000909_1349.LOG" _
, Origin:=xlWindows, StartRow:=1, DataType:=xlDelimited, TextQualifier _
:=xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:= _
False, Comma:=False, Space:=False, Other:=False, FieldInfo:=Array(Array _
(1, 2), Array(2, 1), Array(3, 1), Array(4, 1), Array(5, 1), Array(6, 1), Array(7, 1), Array(8 _
, 1), Array(9, 1), Array(10, 1), Array(11, 1), Array(12, 1), Array(13, 1), Array(14, 1), _
Array(15, 1), Array(16, 1), Array(17, 1), Array(18, 1), Array(19, 1), Array(20, 1), Array( _
21, 1), Array(22, 1), Array(23, 1), Array(24, 1), Array(25, 1), Array(26, 1), Array(27, 1), _
Array(28, 1), Array(29, 1), Array(30, 1), Array(31, 1), Array(32, 1), Array(33, 1), Array( _
34, 1), Array(35, 1), Array(36, 1), Array(37, 1), Array(38, 1), Array(39, 1), Array(40, 1), _
Array(41, 1), Array(42, 1), Array(43, 1), Array(44, 1), Array(45, 1), Array(46, 1), Array( _
47, 1), Array(48, 1), Array(49, 1), Array(50, 1), Array(51, 1), Array(52, 1), Array(53, 1), _
Array(54, 1), Array(55, 1), Array(56, 1), Array(57, 1), Array(58, 1), Array(59, 1), Array( _
60, 1), Array(61, 1), Array(62, 1), Array(63, 1), Array(64, 1), Array(65, 1), Array(66, 1), _
Array(67, 1), Array(68, 1), Array(69, 1), Array(70, 1), Array(71, 1), Array(72, 1), Array( _
73, 1), Array(74, 1), Array(75, 1), Array(76, 1), Array(77, 1), Array(78, 1), Array(79, 1), _
Array(80, 1), Array(81, 1), Array(82, 1), Array(83, 1), Array(84, 1), Array(85, 1), Array( _
86, 1), Array(87, 1), Array(88, 1), Array(89, 1), Array(90, 1), Array(91, 1), Array(92, 1), _
Array(93, 1), Array(94, 1), Array(95, 1), Array(96, 1), Array(97, 1), Array(98, 1), Array( _
99, 1), Array(100, 1))
ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
ActiveWindow.ScrollWorkbookTabs Position:=xlLast
Columns("A:A").EntireColumn.AutoFit
ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
ActiveWindow.ScrollWorkbookTabs Position:=xlFirst
ActiveWindow.SmallScroll Down:=33
ActiveWindow.ScrollRow = 17028
ActiveWindow.ScrollRow = 26783
ActiveWindow.ScrollRow = 29207
ActiveWorkbook.SaveAs FileName:= _
"D:\Edward\Mercury_data_processing_010801\data\PPBreadboard\000911\data.xls", _
FileFormat:=xlNormal, Password:="", WriteResPassword:="", _
ReadOnlyRecommended:=False, CreateBackup:=False
Range("A29210").Select
Workbooks.Open FileName:= _
"D:\Edward\Mercury_data_processing_010801\data\testcase.xls"
Range("B15").Select
ActiveWorkbook.Close
ActiveWorkbook.Close
Sheets("Sheet2").Select
Sheets("Sheet2").Name = "Data"
Range("A1").Select
Workbooks.Open FileName:= _
"D:\Edward\Mercury_data_processing_010801\data\PPBreadboard\000911\data.xls"
ActiveWindow.Visible = False
ActiveSheet.OLEObjects.Add(FileName:= _
"D:\Edward\Mercury_data_processing_010801\data\PPBreadboard\000911\data.xls", _
Link:=False, DisplayAsIcon:=False).Select
Sheets("AutoPlot - GUI").Select
ActiveWorkbook.Save
Sheets("Data").Select
Windows("Worksheet in autoplot_devl_012601").Visible = True
Selection.Verb Verb:=xlPrimary
ActiveWindow.WindowState = xlMaximized
Range("B29214").Select
ActiveWorkbook.Close
Sheets("AutoPlot - GUI").Select
ActiveWorkbook.Save
End Sub

Posted by Mark W. on February 15, 2001 2:00 PM

Geez, did you consider using the Data Text to
Columns... menu command?

Posted by Edward Clutter on February 15, 2001 2:20 PM

How will Data Text to Columns help me? I can't even get Excel to read in the text file. Don't I have to get the text file read in before I can use a feature like that? Besides, because of the delimiters used, microsoft is already recognizing that the data is in columns, so I don't see how your suggestions will help me.
Edward

Posted by Mark W. on February 15, 2001 2:33 PM


>Don't I have to get the text file read in before
>I can use a feature like that?

No. In fact, if you're truly opening (Ctrl+0) a
.txt file from within Excel the Text to Column
wizard should be invoked automatically. How are
you opening this document?

>Besides, because of the delimiters used,
>microsoft is already recognizing that the
>data is in columns, so I don't see how your
>suggestions will help me.

At Step 3 of 3, the Text to Columns wizard gives
you an opportunity to identify columns that you
want to skip (not import).

Posted by Edward Clutter on February 15, 2001 4:05 PM

Ok,
I think we are starting to understand each other. I have never used the text to column mizard, however your comments about it letting me skip columns I don't want sound just like the step I come to when I use the Open command under File and try to open my *.txt and deactivate all of the columns I don't want and only read in the ones I do. I have done this manually and it works just fine, but when I record it as a macro and play it back I get "out of memory". This file is very big ( 20 to 30 columns wide and 10000 to 20000 rows long ), and that is just for one case. In order to plot several cases together, I need to be able to only read in the two columns I need from each case and place them on a spreadsheet and then plot them. Any further thoughts based on that?
Edward



Posted by Mark W. on February 16, 2001 6:45 AM


>Any further thoughts based on that?

Use the Text to Columns Wizard. If you need a macro
use the macro recorder.