VBA FileLen function

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading...

FileLen Function Description

The VBA FileLen function returns the size of a file in bytes. The file size can be returned in kilobytes, megabytes and other similar size units. Scroll down to learn more.

Syntax

The syntax for the FileLen function in VBA is:

FileLen( file_path )

Parameters

file_path
The path to a file name that you wish to retrieve the size for.

Other Notes

The FileLen function returns the size of the file in bytes. If you want the file size to be in:

  • Kilobytes (KB) – divide the result by 1024
  • Megabytes(KB) – divide the result by 1024^2
  • Gigabytes(KB) – divide the result by 1024^3

Example usage

The FileLen function can only be used in VBA code. Let’s look at some FileLen function examples:

FileLen "C:\test.txt"
'Result: 500 (bytes)

FileLen("C:\image.png")/1024
'Result: 25 (kilobytes)