Home Privacy Policy Feedback Link to us Site Map Forums

Excel: SetAttr Function (VBA only)


In Excel, the SetAttr statement allows you to set the attributes of a file.

The syntax for the SetAttr function is:

SetAttr path, attributes

path is the path to a file that you wish to set the attributes for.

attributes are the attributes that you'd like to attribute to the file. Attributes can be the following values:

VB Constant Value Explanation
vbNormal 0 Normal (default)
vbReadOnly 1 Read-only
vbHidden 2 Hidden
vbSystem 4 System file
vbArchive 32 File has been changed since last backup
vbAlias 64 File name is an alias (Macintosh only)

Applies To:

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

For example:

SetAttr "C:\instructions.doc", vbNormal would set the file to Normal
SetAttr "C:\instructions.doc", vbReadOnly + vbHidden would set the file to ReadOnly and Hidden

VBA Code

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

SetAttr "c:\Test\Doc1.doc", vbReadOnly + vbHidden

In this example, the file called Doc1.doc (found in the c:\Test\ directory) would now be set to a ReadOnly, Hidden file.