How to get current working directory using vba?

When one opens an Excel document D:\db\tmp\test1.xlsm:

  • CurDir() returns C:\Users\[username]\Documents

  • ActiveWorkbook.Path returns D:\db\tmp

So CurDir() has a system default and can be changed.

ActiveWorkbook.Path does not change for the same saved Workbook.

For example, CurDir() changes when you do “File/Save As” command, and select a random directory in the File/Directory selection dialog. Then click on Cancel to skip saving. But CurDir() has already changed to the last selected directory.


[ADD]
Resume VBA for different applications

Access D:\db\tmp\test1.accdb, like duckboy81 commented:

  1. CurDir() => C:\Users\[username]\Documents
  2. Application.CurrentProject.Path => D:\db\tmp

Excel D:\db\tmp\test1.xlsm:

  1. CurDir() => C:\Users\[username]\Documents
  2. ActiveWorkbook.Path => D:\db\tmp
  3. Application.DefaultFilePath => C:\Users\[username]\Documents

Outlook:

  1. CurDir() => C:\WINDOWS\System32
  2. Application.Session.Stores(1).Filepath => D:\programdata\Outlook\myOutlookDocX.pst

PowerPoint D:\db\tmp\test1.ppt:

  1. CurDir() => C:\Users\[username]\Documents
  2. ActivePresentation.Path => D:\db\tmp

Word D:\db\tmp\test1.docx:

  1. CurDir() => C:\Users\[username]\Documents
  2. Application.ActiveDocument.Path => D:\db\tmp
  3. Application.ActiveDocument.FullName => D:\db\tmp\test1.docx
  4. Application.StartupPath => C:\users\[username]\appdata\roaming\microsoft\word\startup

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)