VBA LOF Function
In this Article
LOF Description
Returns a Long representing the size, in bytes, of a file opened by using the Open statement.
LOF Syntax
In the VBA Editor, you can type “LOF(” to see the syntax for the LOF Function:
1 |
<strong>LOF</strong>(FileNumber) |
The LOF function contains an argument:
FileNumber: A valid file number.
Examples of Excel VBA LOF Function
To test the LOF function, create a text file “test.txt” on the D drive.(D:\test.txt) Assume that the content of the file is as following.
1 2 3 |
abc 1 2 3 xy z |
Please run the following code.
1 2 3 4 5 |
Sub LOF_Example() Open "D:\test.txt" For Input As #1 MsgBox LOF(1) Close #1 End Sub |
Then, it will show the following dialog.
It means the file size is 16 bytes.
VBA Coding Made Easy
Stop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users!
Learn More!