3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

[Excel VBA]カレントディレクトリの変更

Last updated at Posted at 2019-07-05

ChDir 変更後のパスでも変更できるが、変更先が別のドライブだったり、ネットワーク上だったりすると上手くいかない。そういう時は↓の方法で。

例:カレントディレクトリをネットワーク上にあるxlファイルの場所に変更したい場合

Public Declare PtrSafe Function SetCurrentDirectoryA Lib "kernel32" (ByVal lpPathName As String) As Long

Sub change_directory()
  Debug.Print "変更前: " & CurDir  
  SetCurrentDirectoryA ThisWorkbook.Path
  Debug.Print "変更後: " & CurDir
End Sub

参考
https://social.technet.microsoft.com/Forums/lync/en-US/33551b22-1a10-4c33-abd4-b96b8ec858f3/how-to-change-current-directory-to-a-network-drive-in-vba?forum=excel

3
2
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?