Changing working directory from Excel vba shell

前端 未结 4 1732
广开言路
广开言路 2020-12-11 19:43

For work, I\'m trying to run a Python script from an Excel VBA macro.

The macro is as follows -

Sub Plot()

Shell \"C:\\Users\\maheshda\\AppData\\Lo         


        
4条回答
  •  星月不相逢
    2020-12-11 20:06

    Extending on Wiktor Stribiżew's answer and comments, the sub below can be used to change the Current Directory in any case.

    Public Sub Change_Current_Directory(NewDirectoryPath as string)
        Dim CurrentDirectoryPath as string
        CurrentDirectoryPath = curdir
        if Strings.StrComp(Strings.Left(CurrentDirectoryPath,2), Strings.Left(NewDirectoryPath,2), vbTextCompare) then
            ChDrive Strings.Left(NewDirectoryPath,1)
        end if
        ChDir NewDirectoryPath
    End Function
    

    Happy coding!

提交回复
热议问题