MS Excel: How to use the CHDIR Statement (VBA)
This Excel tutorial explains how to use the Excel CHDIR statement with syntax and examples.
Description
The Microsoft Excel CHDIR statement allows you to change the current directory or folder.
The CHDIR 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 CHDIR statement in Microsoft Excel is:
ChDir path
Parameters or Arguments
- path
- The path that you'd like to set the current directory to.
Returns
The CHDIR statement does not return a value, but rather changes the current directory or folder on the current drive.
Note
- If you need to change drives, try using the CHDRIVE statement first.
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 CHDIR statement can be used in VBA code in Microsoft Excel.
Let's look at some Excel CHDIR statement function examples and explore how to use the CHDIR statement in Excel VBA code:
ChDir "C:\instructions" Result: Sets the current directory to C:\instructions ChDir "C:\Documents\Supplies" Result: Sets the current directory to C:\Documents\Supplies
For example:
ChDir "C:\instructions"
In this example, the current directory would now be changed to C:\instructions.
Advertisements