VBA ChDir Statement
In this Article
Used to change the current directory or folder.
Simple ChDir Examples
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.
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”.
VBA Coding Made EasyStop searching for VBA code online. Learn more about AutoMacro - A VBA Code Builder that allows beginners to code procedures from scratch with minimal coding knowledge and with many time-saving features for all users!