totn Excel Functions

MS Excel: How to use the GETATTR Function (VBA)

This Excel tutorial explains how to use the Excel GETATTR function with syntax and examples.

Description

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

The GETATTR function is a built-in function in Excel that is categorized as a File/Directory Function. It can be used as a VBA function (VBA) in Excel. As a VBA function, you can use this function in macro code that is entered through the Microsoft Visual Basic Editor.

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 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

Returns

The GETATTR function returns an integer value.

Applies To

  • Excel for Office 365, Excel 2019, 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.