Please Note: This article is written for users of the following Microsoft Word versions: 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365. 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.
Written by Allen Wyatt (last updated June 8, 2022)
This tip applies to Word 2007, 2010, 2013, 2016, 2019, and Word in Microsoft 365
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)
Note:
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, 2010, 2013, 2016, 2019, and Word in Microsoft 365. 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.
The First and Last Word on Word! Bestselling For Dummies author Dan Gookin puts his usual fun and friendly candor back to work to show you how to navigate Word 2013. Spend more time working and less time trying to figure it all out! Check out Word 2013 For Dummies today!
There are a variety of methods you can use to get a list of files into a Word document. This tip examines a couple of ...
Discover MoreWant to close or save all your documents at the same time? This trick does it for you.
Discover MoreYour macros can easily add information to the end of an existing text file. This is done by opening the target file in ...
Discover MoreFREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
2022-06-08 15:08:08
ron
Interesting. I'm not familiar with the LOF() command, so I looked it up. I found this
LOF(filenumber) – Length Open File
https://bettersolutions.com/vba/functions/lof-function.htm
Returns the length or size of an open file, in bytes (Long).
.
The file has to be open. You could also use the FILELEN() command without actually opening the file.
.
FILELEN(pathname)
https://bettersolutions.com/vba/functions/filelen-function.htm
Returns the length of a file in bytes (Long).
.
Seems FileLen() is simpler.
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.
Visit the WordTips channel on YouTube
FREE SERVICE: Get tips like this every week in WordTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments