VBA ChDir Statement

ChDir Description

Used to change the current directory or folder.

Simple ChDir Examples

ChDir "C:\ProgramData"

This makes “C:\ProgramData’ the current folder.

The ChDir statement changes the default directory or folder but doesn’t  change the default drive.

So, to change the current folder to the other folder on the other drive, you should use the ChDrive together.

ChDir Syntax

In the VBA Editor, you can type  “ChDir(” to see the syntax for the ChDir Statement:

The ChDir statement contains an argument:

Path: A string expression representing a directory.

Examples of Excel VBA ChDir Function

Sub ChDir_Example1()
    ChDrive "C:\"
    ChDir "C:\Program Files (x86)"
    MsgBox CurDir
End Sub

This changes the current folder to “C:\Program Files (x86)”.

Sub ChDir_Example2()
    ChDrive "C:\"
    ChDir "C:\Windows"
    MsgBox CurDir
End Sub

This changes the current folder to “C:\Windows”.