Learn Excel - Simplify Life with Excel Concepts

Excel GetAttr Function (VBA)

GetAttr Function VBA Code

How to use the GetAttr Function (VBA)

This Excel tutorial explains how to use the Excel GetAttr function with syntax and examples using VBA.


The Excel VBA GetAttr function returns an Integer representing the attributes of a file, directory, or folder.
The Integer value can be a single attribute or a combination of multiple attributes (sum).


To get the attributes information for.


The GetAttr function returns an integer value.




The GetAttr function syntax has the following arguments:

  • pathname: Required. The pathname argument is a string expression that specifies a file name.
    • The pathname may include the directory or folder, and the drive.
    • The value returned by GetAttr is the sum of the following attribute values:
       Constant  Value  Description
       vbNormal  0  (Default) Specifies Normal files.
       vbReadOnly  1  Specifies read-only files.
       vbHidden  2  Specifies hidden files.
       vbSystem  4  Specifies system files. Not available on the Macintosh.
       vbDirectory  16  Specifies directories or folders.
       vbArchive  32   File has changed since last backup. Not available on the Macintosh.
       vbAlias  64  Specified file name is an alias. Available only on the Macintosh.


  • If the specified file is not available then an error will occur.
  • To determine which attributes are set, use the And operator to perform a bitwise comparison of the value returned by the GetAttr function and the value of the individual file attribute you want. If the result is not zero, that attribute is set for the named file.

Useful Links: Link 1Link 2Link 3Link 4