bottom
Great ExcelTips!
         
Your e-mail address is safe!
Close Note

Tips.Net > ExcelTips Home > Files > Determining the Length of a Text File

Determining the Length of a Text File

Summary: When creating a macro to process a text file, you may need to know the length of that file. You can figure this out by using the LOF function, as described in this tip. (This tip works with Microsoft Excel 97, Excel 2000, Excel 2002, Excel 2003, and Excel 2007.)

Several other ExcelTips have discussed opening, reading, writing, appending, and closing text files. Another VBA function associated with sequential text files is the LOF function. If used on an open file, it returns the length of the file, in bytes. In other words, you can determine the number of characters in the file. This can come in handy if you are processing a text file character by character. You can determine the length of the file and then read that many characters before you finish processing the file. The following code fragment is an example of how the LOF function is used:

Open "MyFile.Dat" for Input as #1
FileLen = LOF(1)

Tip #2517 applies to Microsoft Excel versions: 97 | 2000 | 2002 | 2003 | 2007


Save Time! You can have this tip (and several hundred just like it) in the ExcelTips annual archives. Imagine having over 400 tips available at your fingertips, in each annual volume.

Helpful Links

Ask an Excel Question
Make a Comment

Tips.Net Home
Vital News Home

ExcelTips FAQ
ExcelTips Premium

Learn Access Now

Beauty Tips
Bugs and Pests Tips
Car Tips
Cleaning Tips
College Tips
Cooking Tips
Excel2007 Tips
ExcelTips
Family Tips
Gardening Tips
Health Tips
Home Tips
Money Tips
Organizing Tips
Pet Tips
Word2007 Tips
WordTips

Advertise on the
ExcelTips Site

 

Great Info!

Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your e-mail address and click "Subscribe."
     
(Your e-mail address will never be shared with anyone, ever.)