Home |
Search |
Today's Posts |
#2
![]()
Posted to microsoft.public.excel.programming
|
|||
|
|||
![]()
That's what's known as fixed-length field file. Excel can actually import
them directly to a spreadsheet using the data import | Text type feature. But you can work with them in VBA easily enough. I just open the text file and start reading it line by line and parse each line as it's read in using MID$() function. Goes something like this (shows hard coded filename, but you can get it other ways) Dim textFile As String Dim rawData As String Dim filenum As Integer textFile = "C:\My Documents\MyData\newData.txt" filenum = Freefile() Open textFile For Input As #filenum Do While Not EOF(Filenum) Line Input #filenum, rawData myVar = Mid(rawData, 7,11) ....code continues Loop Close #filenum The Mid function grabs characters starting at the first # position for the second # number of characters, so start at 7th characters for 11 characters = columns 7 through 17, inclusive. "Phil" wrote: I would like to use a macro to read in text from a text file that is not delimited and store the data in variables. For example, from line 5 of the text file I want to read from column 7 to 17 and store that value in a variable. After reading in values from various places in the file, I will do some calculations using these numbers, then create a new Excel file and write the calculated numbers into the new file. Is there a way to do this in VBA? |
Thread Tools | Search this Thread |
Display Modes | |
|
|
![]() |
||||
Thread | Forum | |||
Saving as text(tab delimited) file | New Users to Excel | |||
Saving multi-tab excel file created from comma delimited text file | Excel Programming | |||
opening a tab delimited text file | Excel Programming | |||
ADO & semicolon delimited text file? | Excel Programming | |||
Open delimited text file to excel without changing data in that file | Excel Programming |