0

Is there a way to change Excel's working directory using a UNC name?..

This: Changing working directory from Excel vba shell explains how to use ChDir / ChDrive. However, there's no such thing as "Drive"† for a UNC link.

The following naïve code does not change CurDir:

ChDir "\\testserver\longunc\directory"
Debug.Print CurDir()
C:\Documents\ZZZ

And the following obviously fails:

ChDrive "\\testserver\longunc\directory"
Run-time error '5': Invalid procedure call or argument

"Drive"?.. Changing "drive" in 2019?.. How daft is that! Why does this concept even still exist, Microsoft?..

Alexander
  • 313
  • 3
  • 10

1 Answers1

2

You can the SetCurrentDirectory function.

Import to VBA:

Private Declare Function SetCurrentDirectoryA Lib "kernel32" (ByVal lpPathName As String) As Long
EylM
  • 5,967
  • 2
  • 16
  • 28