Hi -
I am trying to write a macro that will open a series of text files in excel, perform text to columns based on fixed width columns (different for each file) and paste the data after the formatting into various tabs of a seperate workbook. I have written the following code that performs as intended but if I paste the code multiple times and update to open different text files and paste to a different tab, eventually excel errors out and says "there are not enough resources to complete this task."
The text files I am opening are not extremely big (maybe 10 columns by 1500 rows at the largest) so I am thinking that my code is inefficient and is leaving something "hanging" or in the clipboard that is eating up way too many resources. If I perform these exact same steps in succession manually I do not get the same error from excel.
The above code is repeated a total of 8 times for each text file and usually by about the 3rd or 4th iteration excel fails.
Please help identify the flaw in my code. Thanks!
I am trying to write a macro that will open a series of text files in excel, perform text to columns based on fixed width columns (different for each file) and paste the data after the formatting into various tabs of a seperate workbook. I have written the following code that performs as intended but if I paste the code multiple times and update to open different text files and paste to a different tab, eventually excel errors out and says "there are not enough resources to complete this task."
The text files I am opening are not extremely big (maybe 10 columns by 1500 rows at the largest) so I am thinking that my code is inefficient and is leaving something "hanging" or in the clipboard that is eating up way too many resources. If I perform these exact same steps in succession manually I do not get the same error from excel.
Code:
Sub Open_Files()
Workbooks.OpenText FileName:= _
"[URL="file://ttcfile10/invacct$/Control/Processing&Monitoring/2011/Item_ACR/Reports/Zero"]\\ttcfile10\invacct$\Control\Processing&Monitoring\2011\Item_ACR\Reports\Zero[/URL] Retail with Cost.txt" _
, Origin:=437, StartRow:=1, DataType:=xlFixedWidth, FieldInfo:=Array( _
Array(0, 1), Array(5, 1), Array(13, 1), Array(20, 1), Array(60, 1), Array(69, 1), Array(76, _
1), Array(91, 1), Array(106, 1), Array(116, 1), Array(126, 1)), TrailingMinusNumbers _
:=True
Cells.Select
Selection.Copy
Windows("Item ACR Combined Template.xlsm").Activate
Sheets("0 Retail with Cost").Select
Cells.Select
ActiveSheet.Paste
Windows("Zero Retail with Cost.txt").Activate
Application.CutCopyMode = False
ActiveWindow.Close
The above code is repeated a total of 8 times for each text file and usually by about the 3rd or 4th iteration excel fails.
Please help identify the flaw in my code. Thanks!