HomePrivacy PolicyFeedbackLink to usSite Map

MS Excel: GetAttr Function (VBA only)


In Excel, the GetAttr function returns an integer that represents the attributes of a file, folder, or directory.

The syntax for the GetAttr function is:

GetAttr ( path )

path is the path to a file, folder, or directory that you wish to retrieve the attributes for.

The GetAttr will return one or a combination of the following values:

VB Constant Value Explanation
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

Applies To:

  • Excel 2007, Excel 2003, Excel XP, Excel 2000

For example:

GetAttr("C:\instructions.doc") would return 0
GetAttr("H:\Documents\Supplies.xls") would return 1

VBA Code

The GetAttr function can only be used in VBA code. For example:

Dim LResult As Integer

LResult = GetAttr("C:\instructions.doc")

In this example, the variable called LResult would now contain the integer representation of the attributes of the instructions.doc file.