Please Note: This article is written for users of the following Microsoft Word versions: 2007 and 2010. If you are using an earlier version (Word 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Word, click here: Determining the Length of a Non-Document Text File.
by Allen Wyatt
(last updated March 24, 2015)
Several other WordTips have discussed opening, reading, writing, appending, and closing text files. Another command 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)
WordTips is your source for cost-effective Microsoft Word training. (Microsoft Word is the most popular word processing software in the world.) This tip (11111) applies to Microsoft Word 2007 and 2010. You can find a version of this tip for the older menu interface of Word here: Determining the Length of a Non-Document Text File.
Do More in Less Time! Are you ready to harness the full power of Word 2013 to create professional documents? In this comprehensive guide you'll learn the skills and techniques for efficiently building the documents you need for your professional and your personal life. Check out Word 2013 In Depth today!
Got a bunch of text that you've imported from a text file? Need to make it look better? You can take a stab at it with this ...Discover More
Word allows you to specify where it should start looking for your documents. This setting can come in handy if you store your ...Discover More
When processing non-document text files in a macro, you have a wide range of commands available for your use. One of those is ...Discover More
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Got a version of Word that uses the ribbon interface (Word 2007 or later)? This site is for you! If you use an earlier version of Word, visit our WordTips site focusing on the menu interface.