|
| ||||||||||
![]() |
| | Thread Tools | Search this Thread |
|
#1
| |||
| |||
| Need help to convert a Text file to Excel via VBA Macro
Example : Code: START-OF-FILE REFNUMBER=12345 DATEFORMAT=yyyymmdd START-OF-FIELDS FIELD1 FIELD2 FIELD3 FIELD4 . . . FIELD120 END-OF-FIELDS START-OF-DATA VALUEA1| VALUEA2| VALUEA3| VALUEA4|. . . | VALUEA120 VALUEB1| VALUEB2| VALUEB3| VALUEB4|. . . | VALUEB120 . . . VALUE(N)| VALUE(N)2| VALUE(N)3| VALUE(N)4|. . . | VALUE(N)120 END-OF-DATA END-OF-FILE Code: FIELD1 FIELD2 FIELD3 FIELD4 . . . . FIELD120 VALUEA1 VALUEA2 VALUEA3 VALUEA4 . . . . VALUEA120 VALUEB1 VALUEB2 VALUEB3 VALUEB4 . . . . VALUEB120 . . . VALUE(N) VALUE(N)2 VALUE(N)3 VALUE(N)4. . . VALUE(N)120 |
|
#2
| |||
| |||
| Re: Need help to convert a Text file to Excel via VBA Macro
Try the below code: Code: Sub Convert()
Open "c:/myfile.txt" For Input As #1
While Not EOF(1)
Input #1, mydata
If mydata = "START-OF-FIELDS" Then
For col = 1 To 120
Input #1, mydata
Cells(1, col) = mydata
Next col
End If
If mydata = "START-OF-DATA" Then
For col = 1 To 120
Input #1, mydata
Cells(2, col) = mydata
Next col
End If
Wend
Close 1
End Sub |
![]() |
|
| Thread Tools | Search this Thread |
| |
Similar Threads for: "Need help to convert a Text file to Excel via VBA Macro" | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| VB Script or batch file to run Excel Macro 2010 | Fakhry | Software Development | 2 | 19-06-2012 12:23 PM |
| How to convert number to text in excel | Jevin | Software Development | 9 | 17-05-2012 06:42 PM |
| How to add commas after each text in each cell using Excel Macro | Raju Chacha | Tips & Tweaks | 2 | 06-01-2012 03:15 PM |
| How to convert image text into a text file | Wadee | Windows Software | 5 | 02-12-2010 05:33 PM |
| Macro to convert file into PDF and then send via email | MAGALY | Software Development | 5 | 09-12-2009 04:00 PM |