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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Importing a Text file into Excel

Status
Not open for further replies.

Crefsupport

Technical User
Mar 13, 2001
1
US
HI,
I'm writing a simple program which converts a text file to an excel file. It opens the file, changes the 1st, 59th and 60th columns to text and then saves it as an excel file. I recorded the macro, but when I tried to compile it I received an "Out of Memory" problem. I then read up on the OpenText function and learned that I did not have to include each column array in the fieldarray option. However, when I do this, it changes the first 3 column to text. I don't know what to do. Can anyone offer some suggestions? Here is my code:

Sub Convert_File()
Dim file_date, file_name, Response As String
Dim i As Integer
Dim track_names As Variant
track_names = Array("CREF_Growth(CGA)", "Global_Equities(GEA)", "Mut_Fund_Gr&Inc(MFGI)", "Mut_Fund_Growth(MFGE)", _
"Mut_Fund_Int'l_Equities(MFIE)", "Inst_MF_Gr&Inc(IMGI)", "Inst_MF_Growth(IMGE)", "Inst_MF_Int'l_Equities(IMIE)", _
"NYS_Growth", "Stock_Int'l", "Stock_Domestic", "Life_MF_Int'l_Equities(PAIE)", "Stock_Account", _
"Euro_Superactive", "GEA_Active", "GEA_Enhanced_Index", "USA_ValueII", "Dom_Superactive", _
"Int'l_Superactive", "Fareast_superactive", "CGA_Enh_Ind2", "Japan_Superactive")

file_date = InputBox("Please enter the date: (mmdd format)", "Date")
If file_date <> &quot;&quot; Then
For i = 0 To 21
file_name = track_names(i) & file_date
Save_It (file_name)
Cells.Select
Cells.EntireColumn.AutoFit
ActiveWorkbook.SaveAs FileName:=&quot;h:\&quot; & file_name & &quot;.xls&quot;, _
FileFormat:=xlWorkbookNormal
ActiveWorkbook.Close SaveChanges = False
Next i
Response = MsgBox(&quot;Done!&quot;, vbOKOnly)
End If
Workbooks(&quot;Tracking_System.XLS&quot;).Close SaveChanges:=False
End Sub
Sub Save_It(save_file As String)

'
' Macro2 Macro
' Macro recorded 3/9/01 by CREF
'

'
Workbooks.OpenText FileName:=&quot;P:\Track_it\Data\CREF_GROWTH(CGA)0302.TXT&quot;, _
Origin:=xlWindows, Tab:=True, _
FieldInfo:=Array(Array(59, 2), Array(60, 2), Array(1, 2), Array(2, 1))


End Sub


Originally, I recorded:
Sub Macro2()
'
' Macro2 Macro
' Macro recorded 3/12/01 by CREF
'

'
Workbooks.Open FileName:=&quot;C:\MUT_FUND_INT'L_EQUITIES(MFIE).xls&quot;
ActiveWorkbook.Close
'Workbooks.OpenText FileName:=&quot;C:\MUT_FUND_INT'L_EQUITIES(MFIE)0302.txt&quot;, _
' Origin:=xlWindows, StartRow:=1, DataType:=xlDelimited, TextQualifier:= _
' xlDoubleQuote, ConsecutiveDelimiter:=False, Tab:=True, Semicolon:=False, _
' Comma:=False, Space:=False, Other:=False, FieldInfo:=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(59, 2), Array(60, 2), Array(61, 1))
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top