Returns a Long representing the size, in bytes, of a file opened by using the Open statement.
In the VBA Editor, you can type “LOF(” to see the syntax for the LOF Function:
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.
abc 1 2 3 xy z
Please run the following code.
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 EasyStop 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!