VBA GetAttr function

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 4.00 out of 5)

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:


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:

Example usage

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