The VBA FileAttr function returns an integer, representing the mode (or system file handle) of a file that has been opened using the VBA Open statement.
The syntax of the function is:
Where the arguments are as follows:
|FileNumber||-||The file number associated to the file that you are querying.|
If the [ReturnType] argument is set to 1 (or is omitted), the FileAttr function returns an integer, representing the mode of the specified file. This may be any of the following:
In the example below, the VBA FileAttr function is used to return the mode of two open files.
' Get the mode of the file data2.txt.
fmode2 = FileAttr( 2 )
' fmode2 is now equal to 2 (indicates file open for Output).
Note that, in both of the above calls to the FileAttr function, the [ReturnType] argument is omitted and so the default value 1 is used (meaning the mode of the supplied file should be returned).
Therefore, after running the above VBA code:
If the FileAttr function is supplied with a FileNumber that does not exist, you will get the error:
If the [ReturnType] argument is set to 2, and the current system is not a 16-bit system, you will get the error: