Microsoft KB Archive/190032

= "File not loaded completely" error importing text files larger than 65536 rows in Mac XL =

Article ID: 190032

Article Last Modified on 1/23/2007

-

APPLIES TO


 * Microsoft Excel 2004 for Mac
 * Microsoft Excel X for Mac
 * Microsoft Excel 2001 for Mac
 * Microsoft Excel 98 for Macintosh

-



This article was previously published under Q190032





SYMPTOMS
If you open a text file in Microsoft Excel that contains more than 65536 rows, you may receive the following error message

File not loaded completely

and the text file is truncated at row 65536.



CAUSE
Worksheets in Excel have a limit of 65536 rows.



WORKAROUND
You can use a Visual Basic for Applications macro to open the file and automatically break the text into multiple worksheets. The "More Information" section of this article contains a sample macro to open a text file with more than 65536 rows.



STATUS
This is by design of Microsoft Excel.



MORE INFORMATION
The following sample macro prompts you for a text file name, and then opens the file in memory. If the number of rows is larger than the Microsoft Excel worksheet limit of 65536, the macro breaks the file into multiple worksheets. This macro applies only to files you saved as text files and does not apply to any other file formats. The macro will not work with database file formats.

Note that because this is a macro, using it may be significantly slower than clicking Open on the File menu.

Microsoft provides programming examples for illustration only, without warranty either expressed or implied. This includes, but is not limited to, the implied warranties of merchantability or fitness for a particular purpose. This article assumes that you are familiar with the programming language that is being demonstrated and with the tools that are used to create and to debug procedures. Microsoft support engineers can help explain the functionality of a particular procedure, but they will not modify these examples to provide added functionality or construct procedures to meet your specific requirements. ' All lines that begin with an apostrophe (') are remarks and are not ' required for the macro to run.

Sub LargeFileImport

' Dimension Variables. Dim ResultStr As String Dim FileName As Variant Dim FileNum As Integer Dim Counter As Double

' Ask User for file's name. FileName = Application.GetOpenFilename("TEXT")

' Check for no entry. If FileName = False Then End

' Get next available file handle number. FileNum = FreeFile

' Open text file for input. Open FileName For Input As #FileNum

' Turn screen updating off. Application.ScreenUpdating = False

' Create a new workbook with one worksheet in it. Workbooks.Add template:=xlWorksheet

Counter = 1 ' Loop until the end of file is reached. Do While Seek(FileNum) <= LOF(FileNum) ' Display importing row number on status bar. Application.StatusBar = "Importing Row " & _ Counter & " of text file " & FileName ' Store one line of text from file to variable. Line Input #FileNum, ResultStr ' Store variable data into active cell. If Left(ResultStr, 1) = "=" Then ActiveCell.Value = "'" & ResultStr Else ActiveCell.Value = ResultStr End If         If ActiveCell.Row = 65536 Then ' If on the last row then add a new sheet. ActiveWorkbook.Sheets.Add Else ' If not the last row then go one cell down. ActiveCell.Offset(1, 0).Select End If         ' Increment the counter by 1. Counter = Counter + 1 ' Start again at top of 'do while' statement. Loop ' Close the open text file. Close ' Remove message from status bar. Application.StatusBar = False

End Sub NOTE: The macro does not parse the data into columns. After using the macro, you may also need to use the Text To Columns command on the Data menu to parse the data as needed.

