VBA GetAttr function

GetAttr Function Description

The VBA GetAttr function returns an Integer result with the attributes of a file or directory. The result can be a single attribute or a combination of multiple attributes (sum). Attribute values are multiplications of the number 2 hence binary attribute values can be identified. To learn more scroll down.


The syntax for the GetAttr function in VBA is:

GetAttr ( path )


The path to a file or directory that you wish to retrieve the attributes for.

Other Notes

The GetAttr function returns one or a combination of multiple of the following values:

Constant Value Description
vbNormal 0 Normal
vbReadOnly 1 Read-only
vbHidden 2 Hidden
vbSystem 4 System file
vbDirectory 16 Directory or folder
vbArchive 32 File has been changed since last backup
vbAlias 64 File name is an alias

Other Notes

The result of the GetAttr function can be a combination of several attributes. To validate whether a single constant attribute is included in the combination simply execute a binary operation on the result of the GetAttr function and the constant attribute:

If GetAttr("C:\Program Files") And vbDirectory > 0 then
  Debug.Print "Is Directory"
End if

Example usage

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

GetAttr "C:\test.txt"
Result: 0 (vbNormal)

GetAttr "C:\Program Files"
Result: 17 (vbNormal + vbDirectory)