0

I am using excel macro button in my excel file. on clicking that button one python script get called and that script is in D drive. and in that script I am doing os.getcwd().It should give me D drive but instead its giving me C drive.

I am expecting that it should give me D drive path for os.getcwd as it present in D drive but giving me c drive

  • Can you share the excel macro you run the python script with? – Tzane May 19 '23 at 10:43
  • Sub RunPythonScript() Dim shell As Object Set shell = VBA.CreateObject("WScript.Shell") Dim pythonExePath As String pythonExePath = """C:\Users\xxx\AppData\Local\Programs\Python\Python39\python.exe""" Dim pythonScriptPath As String pythonScriptPath = "D:\xxx\main.py" Dim cmd As String cmd = "cmd.exe /c " & pythonExePath & " " & pythonScriptPath & " & pause" shell.Run cmd, 1, True End Sub – almost there May 19 '23 at 12:11
  • The working directory for the [shell is determined by `shell.CurrentDirectory`](https://devblogs.microsoft.com/scripting/how-can-i-change-the-working-folder-of-a-script/), not sure what the default is. Depending on what you actually wanna do, parsing directories might be easier in VBA or python. – Tzane May 19 '23 at 12:28

0 Answers0