Learn Excel - Simplify Life with Excel Concepts

Excel MkDir Function (VBA)

SetAttr Function VBA Code

How to use the SetAttr Function (VBA)

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


The Excel VBA SetAttr function allows you to set the attributes of a file.


To sets the attributes of a file or directory.


The SetAttr function does not return a value, but rather sets the attributes of a file.


SetAttr pathname, attributes


The SetAttr function syntax has the following arguments:

  • pathname: Required. The pathname argument is a string expression that specifies a file name; may include directory or folder, and drive.
  • attributes: Required. Constant or numeric expression whose sum specifies file attributes.
  • The attributes argument settings are:
     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.
     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 you try to set the attributes of an open file, a run-time error occurs.

Useful Links: Link 1Link 2Link 3Link 4