Saturday, August 13, 2016

How to use the GETATTR Function (VBA)

Description

The Microsoft Excel GETATTR function returns an integer that represents the attributes of a file, folder, or directory.

Syntax

The syntax for the GETATTR function in Microsoft Excel is:
GetAttr ( path )

Parameters or Arguments

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

Note

  • The GETATTR function will return one or a combination of the following values:
    VB ConstantValueExplanation
    vbNormal0Normal
    vbReadOnly1Read-only
    vbHidden2Hidden
    vbSystem4System file
    vbDirectory16Directory or folder
    vbArchive32File has been changed since last backup
    vbAlias64File name is an alias

Applies To

  • Excel 2016, Excel 2013, Excel 2011 for Mac, Excel 2010, Excel 2007, Excel 2003, Excel XP, Excel 2000

Type of Function

  • VBA function (VBA)

Example (as VBA Function)

The GETATTR function can only be used in VBA code in Microsoft Excel.
Let's look at some Excel GETATTR function examples and explore how to use the GETATTR function in Excel VBA code:
GetAttr("C:\instructions.doc")
Result: 0

GetAttr("H:\Documents\Supplies.xls")
Result: 1
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.