Returns the value indicating if the end of a file has been reached (Boolean).
In the VBA Editor, you can type “EOF(” to see the syntax for the EOF Function:
The EOF function contains an argument:
FileNumber: Any valid file number.
Examples of Excel VBA EOF Function
To test the EOF 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
Please run the following code.
Dim strContent As String
Open "D:\test.txt" For Input As #1 ' Open file.
Do While Not EOF(1) ' Loop until end of file.
MyChar = Input(1, #1) ' Get one character.
strContent = strContent & MyChar '
Close #1 ' Close file.
Then, the result will be as following.
Here, used EOF function to determine that the end of a file has been reached.
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!