Please Note: This article is written for users of the following Microsoft Excel versions: 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. If you are using an earlier version (Excel 2003 or earlier), this tip may not work for you. For a version of this tip written specifically for earlier versions of Excel, click here: Determining the Current Directory.
Written by Allen Wyatt (last updated November 18, 2024)
This tip applies to Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021
If you are programming macros in VBA, it is often helpful to know the directory that Windows feels is the current one. You can find out which directory is current by using the following syntax:
MyDir = CurDir
When this line is executed, MyDir (a string) will be equal to the full path of the current directory.
Understand that the path returned by CurDir is the path that Windows feels is the current directory, not the path that Excel feels is the current directory. In other words, CurDir won't return a path equal to the current path in which you are working with your workbooks. CurDir reflects the directory set using the ChDir command, which is detailed in a different ExcelTip.
Note:
ExcelTips is your source for cost-effective Microsoft Excel training. This tip (9363) applies to Microsoft Excel 2007, 2010, 2013, 2016, 2019, Excel in Microsoft 365, and 2021. You can find a version of this tip for the older menu interface of Excel here: Determining the Current Directory.
Create Custom Apps with VBA! Discover how to extend the capabilities of Office 2013 (Word, Excel, PowerPoint, Outlook, and Access) with VBA programming, using it for writing macros, automating Office applications, and creating custom applications. Check out Mastering VBA for Office 2013 today!
Need to select a cell using a macro? Need that selection to be relative to the cell you currently have selected? Here are ...
Discover MoreYou can use macros to make your common Excel tasks easier and faster. For instance, if you routinely need to create new ...
Discover MoreWhen creating a workbook to be used by others, you may want any worksheets they add to the workbook to contain some ...
Discover MoreFREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
2019-09-24 05:44:44
Harold Druss
Sub DisplayWorkbookPath()
MsgBox ActiveWorkbook.Path, vbInformation, "Workbook Path"
End Sub
2019-09-23 10:28:40
JC
My suggestion is to avoid CurDir and explicitly code paths.
Got a version of Excel that uses the ribbon interface (Excel 2007 or later)? This site is for you! If you use an earlier version of Excel, visit our ExcelTips site focusing on the menu interface.
FREE SERVICE: Get tips like this every week in ExcelTips, a free productivity newsletter. Enter your address and click "Subscribe."
Copyright © 2024 Sharon Parq Associates, Inc.
Comments