'カレントディレクトリを変更するマクロ Private Declare Function GetCurrentDirectory Lib "kernel32" Alias "GetCurrentDirectoryA" ( _ ByVal cchCurDir As Long, ByVal lpszCurDir As String) As Long Private Declare Function SetCurrentDirectory Lib "kernel32" Alias "SetCurrentDirectoryA" ( _ ByVal lpszCurDir As String) As Long Public Function GetCurDir() As String Const MAX_PATH As Long = 260 Dim sBuffer As String Dim iLength As Long GetCurDir = "" sBuffer = String$(MAX_PATH, Chr$(0)) iLength = GetCurrentDirectory(MAX_PATH + 1, sBuffer) If iLength = 0 Then Exit Function End If If iLength <= MAX_PATH Then GetCurDir = Left$(sBuffer, InStr(1, sBuffer, Chr$(0), 0) - 1) End If End Function Public Function SetCurDir(ByVal sDir As String) As Boolean SetCurDir = (SetCurrentDirectory(sDir) <> 0) End Function Sub Test() SetCurDir "C:\Work" MsgBox GetCurDir() End Sub